Skip to content

Commit

Permalink
Merge branch 'develop' into feat/5741
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored Nov 7, 2024
2 parents 52dc7f5 + cc874d2 commit 2e1bdd6
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SmoothProductCardFound extends StatelessWidget {
Icon(
Icons.circle,
size: 15,
color: helper.getButtonColor(isDarkMode),
color: helper.getColor(context),
),
const Padding(
padding: EdgeInsetsDirectional.only(
Expand Down
50 changes: 12 additions & 38 deletions packages/smooth_app/lib/helpers/product_compatibility_helper.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';

class ProductCompatibilityHelper {
ProductCompatibilityHelper.product(final MatchedProductV2 product)
Expand All @@ -11,20 +11,18 @@ class ProductCompatibilityHelper {

final MatchedProductStatusV2 status;

Color getHeaderBackgroundColor(bool darkMode) {
if (darkMode) {
return _getDarkColors();
} else {
return _getLightColors();
}
}
Color getColor(BuildContext context) {
final SmoothColorsThemeExtension theme =
Theme.of(context).extension<SmoothColorsThemeExtension>()!;

Color getButtonColor(bool darkMode) {
if (darkMode) {
return _getLightColors();
} else {
return _getDarkColors();
}
return switch (status) {
MatchedProductStatusV2.VERY_GOOD_MATCH => theme.green,
MatchedProductStatusV2.GOOD_MATCH => theme.green,
MatchedProductStatusV2.POOR_MATCH => theme.orange,
MatchedProductStatusV2.MAY_NOT_MATCH => theme.orange,
MatchedProductStatusV2.DOES_NOT_MATCH => theme.red,
MatchedProductStatusV2.UNKNOWN_MATCH => theme.greyNormal,
};
}

Color getHeaderForegroundColor(bool darkMode) =>
Expand All @@ -33,30 +31,6 @@ class ProductCompatibilityHelper {
Color getButtonForegroundColor(bool darkMode) =>
getHeaderForegroundColor(darkMode);

// According to color contrast tool https://material.io/resources/color
// on all those background colors the best is to write in black.
Color _getDarkColors() {
switch (status) {
case MatchedProductStatusV2.VERY_GOOD_MATCH:
return DARK_GREEN_COLOR;
case MatchedProductStatusV2.GOOD_MATCH:
return LIGHT_GREEN_COLOR;
case MatchedProductStatusV2.POOR_MATCH:
return DARK_YELLOW_COLOR;
case MatchedProductStatusV2.MAY_NOT_MATCH:
return DARK_ORANGE_COLOR;
case MatchedProductStatusV2.DOES_NOT_MATCH:
return RED_COLOR;
case MatchedProductStatusV2.UNKNOWN_MATCH:
return FAIR_GREY_COLOR;
}
}

Color _getLightColors() {
// TODO(monsieurtanuki): difference between dark and light
return _getDarkColors();
}

String getHeaderText(final AppLocalizations appLocalizations) {
switch (status) {
case MatchedProductStatusV2.VERY_GOOD_MATCH:
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3073,5 +3073,9 @@
"photo_viewer_details_url_title": "URL",
"@photo_viewer_details_url_title": {
"description": "Label for the link of a photo"
},
"product_page_compatibility_score": "Compatible",
"@product_page_compatibility_score": {
"description": "Compatibility score on top of the product page. The sentence is \"100%\" Compatible"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class _PersonalizedRankingPageState extends State<PersonalizedRankingPage>
barcode: matchedProduct.barcode,
backgroundColor:
ProductCompatibilityHelper.status(matchedProduct.status)
.getHeaderBackgroundColor(darkMode)
.getColor(context)
.withAlpha(_backgroundAlpha),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class _CompareProducts3PageState extends State<CompareProducts3Page> {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
context.watch<LocalDatabase>();

final bool darkMode = Theme.of(context).brightness == Brightness.dark;

final ProductPreferences productPreferences =
context.watch<ProductPreferences>();
final List<List<Attribute>> scoreAttributesArray = <List<Attribute>>[];
Expand All @@ -85,7 +83,7 @@ class _CompareProducts3PageState extends State<CompareProducts3Page> {
scoreWidgets.add(
Expanded(
child: Container(
color: helper.getHeaderBackgroundColor(darkMode),
color: helper.getColor(context),
child: Center(
child: Text(
matchedProduct.score.toInt().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ProductCompatibilityHeader extends StatelessWidget {
product,
productPreferences,
);

final ProductCompatibilityHelper helper =
ProductCompatibilityHelper.product(matchedProduct);
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand All @@ -33,7 +34,7 @@ class ProductCompatibilityHeader extends StatelessWidget {

return Ink(
decoration: BoxDecoration(
color: helper.getHeaderBackgroundColor(isDarkMode),
color: helper.getColor(context),
// Ensure that the header has the same circular radius as the SmoothCard.
borderRadius: const BorderRadiusDirectional.only(
topStart: ROUNDED_RADIUS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ class _ProductFooterFilledButton extends StatelessWidget {
Widget build(BuildContext context) {
final SmoothColorsThemeExtension themeExtension =
Theme.of(context).extension<SmoothColorsThemeExtension>()!;
final ProductPageCompatibility compatibility =
context.watch<ProductPageCompatibility>();

return Semantics(
excludeSemantics: true,
Expand All @@ -374,9 +376,11 @@ class _ProductFooterFilledButton extends StatelessWidget {
onPressed: onTap,
style: OutlinedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: context.lightTheme()
? themeExtension.primaryBlack
: themeExtension.primarySemiDark,
backgroundColor: compatibility.score > 0
? compatibility.color
: context.lightTheme()
? themeExtension.primaryBlack
: themeExtension.primarySemiDark,
side: BorderSide.none,
),
child: Row(
Expand Down
Loading

0 comments on commit 2e1bdd6

Please sign in to comment.