From cf8fad551442b4be4c4a51942e5af5e50b67c935 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Mon, 10 Jun 2024 08:31:32 +0200 Subject: [PATCH 1/2] feat: 5198 - added a local "latest prices" page Impacted files: * `app_en.arb`: added 1 "product unknown" label * `app_fr.arb`: added 1 "product unknown" label * `price_data_widget.dart`: minor fix * `price_product_widget.dart`: minor improvements * `user_preferences_account.dart: added a call to a "latest prices" page --- packages/smooth_app/lib/l10n/app_en.arb | 1 + packages/smooth_app/lib/l10n/app_fr.arb | 1 + .../preferences/user_preferences_account.dart | 28 +++++++++- .../lib/pages/prices/price_data_widget.dart | 3 ++ .../pages/prices/price_product_widget.dart | 54 ++++++++++++------- 5 files changed, 65 insertions(+), 22 deletions(-) diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 823d5ce191bb..d0c4a38537fa 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -1706,6 +1706,7 @@ "prices_add_validation_error": "Validation error", "prices_privacy_warning_title": "Privacy warning", "prices_privacy_warning_message": "Prices will be public, along with the store they refer to.\nThat might allow people who know about your Open Food Facts pseudonym to:\n* infer in which area you live\n* know what you are buying\nIf you are uneasy with that, please change your pseudonym, or create a new Open Food Facts account and log into the app with it.", + "prices_unknown_product": "Unknown product", "dev_preferences_import_history_result_success": "Done", "@dev_preferences_import_history_result_success": { "description": "User dev preferences - Import history - Result successful" diff --git a/packages/smooth_app/lib/l10n/app_fr.arb b/packages/smooth_app/lib/l10n/app_fr.arb index b46bdef21b32..2b724bea3b8e 100644 --- a/packages/smooth_app/lib/l10n/app_fr.arb +++ b/packages/smooth_app/lib/l10n/app_fr.arb @@ -1706,6 +1706,7 @@ "prices_add_validation_error": "Erreur de validation", "prices_privacy_warning_title": "Avertissement de confidentialité", "prices_privacy_warning_message": "Les prix seront publics, ainsi que le magasin auquel ils font référence.\nCela pourrait permettre aux personnes qui connaissent votre pseudonyme Open Food Facts de :\n* déduire dans quelle région vous habitez\n* savoir ce que vous achetez\nSi vous êtes pas à l'aise avec cela, veuillez changer votre pseudonyme ou créer un nouveau compte Open Food Facts et vous connecter à l'application avec celui-ci.", + "prices_unknown_product": "Produit inconnu", "dev_preferences_import_history_result_success": "Fait", "@dev_preferences_import_history_result_success": { "description": "User dev preferences - Import history - Result successful" diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart index beddecb53749..e2411941db1d 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart @@ -244,9 +244,33 @@ class UserPreferencesAccount extends AbstractUserPreferences { CupertinoIcons.money_dollar_circle, myCount: _getMyPricesCount(), ), - _getPriceListTile( + _getListTile( appLocalizations.all_search_prices_latest_title, - 'app/prices', + () async => Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => PricesPage( + GetPricesModel( + parameters: GetPricesParameters() + ..orderBy = >[ + const OrderBy( + field: GetPricesOrderField.created, + ascending: false, + ), + ] + ..pageSize = GetPricesModel.pageSize + ..pageNumber = 1, + displayOwner: true, + displayProduct: true, + uri: OpenPricesAPIClient.getUri( + path: 'app/prices', + uriHelper: ProductQuery.uriProductHelper, + ), + title: appLocalizations.all_search_prices_latest_title, + ), + ), + ), + ), + CupertinoIcons.money_dollar_circle, ), _getPriceListTile( appLocalizations.all_search_prices_top_user_title, diff --git a/packages/smooth_app/lib/pages/prices/price_data_widget.dart b/packages/smooth_app/lib/pages/prices/price_data_widget.dart index 62e0eee983df..cf2bf4cdefdc 100644 --- a/packages/smooth_app/lib/pages/prices/price_data_widget.dart +++ b/packages/smooth_app/lib/pages/prices/price_data_widget.dart @@ -36,6 +36,9 @@ class PriceDataWidget extends StatelessWidget { if (price.product == null) { return null; } + if (price.product!.quantity == null) { + return null; + } if ((price.product!.quantityUnit ?? 'g') != 'g') { return null; } diff --git a/packages/smooth_app/lib/pages/prices/price_product_widget.dart b/packages/smooth_app/lib/pages/prices/price_product_widget.dart index 6fca9259a4f0..68f1408159df 100644 --- a/packages/smooth_app/lib/pages/prices/price_product_widget.dart +++ b/packages/smooth_app/lib/pages/prices/price_product_widget.dart @@ -1,5 +1,6 @@ import 'package:auto_size_text/auto_size_text.dart'; 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/generic_lib/widgets/images/smooth_image.dart'; @@ -16,7 +17,9 @@ class PriceProductWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final String? name = priceProduct.name; + final AppLocalizations appLocalizations = AppLocalizations.of(context); + final String name = priceProduct.name ?? priceProduct.code; + final bool unknown = priceProduct.name == null; final String? imageURL = priceProduct.imageURL; final int priceCount = priceProduct.priceCount; final List? brands = priceProduct.brands?.split(','); @@ -32,30 +35,31 @@ class PriceProductWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (imageURL != null) - SizedBox( - width: _imageSize, - child: SmoothImage( - width: _imageSize, - height: _imageSize, - imageProvider: NetworkImage(imageURL), - ), - ), - if (imageURL != null) const SizedBox(width: SMALL_SPACE), SizedBox( - width: imageURL == null - ? constraints.maxWidth - : constraints.maxWidth - _imageSize - SMALL_SPACE, + width: _imageSize, + child: imageURL == null + ? const Icon( + Icons.question_mark, + size: _imageSize / 2, + ) + : SmoothImage( + width: _imageSize, + height: _imageSize, + imageProvider: NetworkImage(imageURL), + ), + ), + const SizedBox(width: SMALL_SPACE), + SizedBox( + width: constraints.maxWidth - _imageSize - SMALL_SPACE, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (name != null) - AutoSizeText( - name, - maxLines: 2, - style: Theme.of(context).textTheme.titleMedium, - ), + AutoSizeText( + name, + maxLines: 2, + style: Theme.of(context).textTheme.titleMedium, + ), Wrap( spacing: VERY_SMALL_SPACE, crossAxisAlignment: WrapCrossAlignment.center, @@ -69,6 +73,16 @@ class PriceProductWidget extends StatelessWidget { onPressed: () {}, ), if (quantity != null) Text(quantity), + if (unknown) + PriceButton( + title: appLocalizations.prices_unknown_product, + iconData: Icons.warning, + onPressed: null, + buttonStyle: ElevatedButton.styleFrom( + disabledForegroundColor: Colors.red, + disabledBackgroundColor: Colors.red[100], + ), + ), ], ), ], From 019e953f7157a1ec086ed2f95a556c0da603024f Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Mon, 10 Jun 2024 08:36:45 +0200 Subject: [PATCH 2/2] Added comments --- packages/smooth_app/lib/l10n/app_en.arb | 3 +++ packages/smooth_app/lib/l10n/app_fr.arb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index d0c4a38537fa..cd6add50caf6 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -1707,6 +1707,9 @@ "prices_privacy_warning_title": "Privacy warning", "prices_privacy_warning_message": "Prices will be public, along with the store they refer to.\nThat might allow people who know about your Open Food Facts pseudonym to:\n* infer in which area you live\n* know what you are buying\nIf you are uneasy with that, please change your pseudonym, or create a new Open Food Facts account and log into the app with it.", "prices_unknown_product": "Unknown product", + "@prices_unknown_product": { + "description": "Very small text, in the context of prices, to say that the product is unknown" + }, "dev_preferences_import_history_result_success": "Done", "@dev_preferences_import_history_result_success": { "description": "User dev preferences - Import history - Result successful" diff --git a/packages/smooth_app/lib/l10n/app_fr.arb b/packages/smooth_app/lib/l10n/app_fr.arb index 2b724bea3b8e..e51e2954b39f 100644 --- a/packages/smooth_app/lib/l10n/app_fr.arb +++ b/packages/smooth_app/lib/l10n/app_fr.arb @@ -1707,6 +1707,9 @@ "prices_privacy_warning_title": "Avertissement de confidentialité", "prices_privacy_warning_message": "Les prix seront publics, ainsi que le magasin auquel ils font référence.\nCela pourrait permettre aux personnes qui connaissent votre pseudonyme Open Food Facts de :\n* déduire dans quelle région vous habitez\n* savoir ce que vous achetez\nSi vous êtes pas à l'aise avec cela, veuillez changer votre pseudonyme ou créer un nouveau compte Open Food Facts et vous connecter à l'application avec celui-ci.", "prices_unknown_product": "Produit inconnu", + "@prices_unknown_product": { + "description": "Very small text, in the context of prices, to say that the product is unknown" + }, "dev_preferences_import_history_result_success": "Fait", "@dev_preferences_import_history_result_success": { "description": "User dev preferences - Import history - Result successful"