Skip to content

Commit

Permalink
feat: 5198 - added a local "latest prices" page (#5351)
Browse files Browse the repository at this point in the history
* 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

* Added comments
  • Loading branch information
monsieurtanuki authored Jun 10, 2024
1 parent 2ab154e commit 39c9c43
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 22 deletions.
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 @@ -1706,6 +1706,10 @@
"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",
"@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"
Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,10 @@
"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",
"@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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(
builder: (BuildContext context) => PricesPage(
GetPricesModel(
parameters: GetPricesParameters()
..orderBy = <OrderBy<GetPricesOrderField>>[
const OrderBy<GetPricesOrderField>(
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,
Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/pages/prices/price_data_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
54 changes: 34 additions & 20 deletions packages/smooth_app/lib/pages/prices/price_product_widget.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<String>? brands = priceProduct.brands?.split(',');
Expand All @@ -32,30 +35,31 @@ class PriceProductWidget extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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: <Widget>[
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,
Expand All @@ -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],
),
),
],
),
],
Expand Down

0 comments on commit 39c9c43

Please sign in to comment.