dynamic
build(- dynamic context
)
Implementation
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final UserPreferences userPreferences = context.watch<UserPreferences>();
final ProductPreferences productPreferences =
context.watch<ProductPreferences>();
final Size screenSize = MediaQuery.of(context).size;
final ThemeData themeData = Theme.of(context);
final bool isDarkMode = themeData.colorScheme.brightness == Brightness.dark;
final List<String> excludedAttributeIds =
userPreferences.getExcludedAttributeIds();
final List<Widget> scores = <Widget>[];
final double iconSize = IconWidgetSizer.getIconSizeFromContext(context);
final List<Attribute> attributes = getPopulatedAttributes(
product,
SCORE_ATTRIBUTE_IDS,
excludedAttributeIds,
);
for (final Attribute attribute in attributes) {
scores.add(SvgIconChip(attribute.iconUrl!, height: iconSize));
}
final MatchedProduct matchedProduct = MatchedProduct.getMatchedProduct(
product,
productPreferences,
userPreferences,
);
final ProductCompatibilityHelper helper =
ProductCompatibilityHelper(matchedProduct);
return GestureDetector(
onTap: onTap ??
() async {
await Navigator.push<Widget>(
context,
MaterialPageRoute<Widget>(
builder: (BuildContext context) => ProductPage(product),
),
);
refresh?.call();
},
onLongPress: () {
onLongPress?.call();
},
child: Hero(
tag: heroTag,
child: SmoothCard(
elevation: elevation,
color: backgroundColor,
padding: const EdgeInsets.all(VERY_SMALL_SPACE),
child: Row(
children: <Widget>[
SmoothProductImage(
product: product,
width: screenSize.width * 0.20,
height: screenSize.width * 0.20,
),
const Padding(padding: EdgeInsets.only(left: VERY_SMALL_SPACE)),
Expanded(
child: SizedBox(
height: screenSize.width * 0.2,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
getProductName(product, appLocalizations),
overflow: TextOverflow.ellipsis,
style: themeData.textTheme.headline4,
),
Text(
product.brands ?? appLocalizations.unknownBrand,
overflow: TextOverflow.ellipsis,
style: themeData.textTheme.subtitle1,
),
Row(
children: <Widget>[
Icon(
Icons.circle,
size: 15,
color: helper.getButtonColor(isDarkMode),
),
const Padding(
padding: EdgeInsets.only(left: VERY_SMALL_SPACE)),
Text(
helper.getSubtitle(appLocalizations),
style: themeData.textTheme.bodyText2!.apply(
color: helper
.getButtonForegroundColor(isDarkMode)),
),
],
),
],
),
),
),
const Padding(padding: EdgeInsets.only(left: VERY_SMALL_SPACE)),
Padding(
padding: const EdgeInsets.all(VERY_SMALL_SPACE),
child: Column(
children: scores,
),
),
],
),
),
),
);
}