From 502db5714ea1714a78e1b6f38f6d6c952619dcbd Mon Sep 17 00:00:00 2001 From: danagbemava Date: Thu, 10 Feb 2022 20:53:35 +0000 Subject: [PATCH 1/4] feat: add string for retry button --- packages/smooth_app/lib/l10n/app_en.arb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 3c367c4041a..c27d47e94c3 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -572,5 +572,6 @@ "compare_products_mode": "Compare Mode", "@compare_products_mode": { "description": "Button to switch to 'compare products mode'" - } -} \ No newline at end of file + }, + "retry_button_label": "Retry" +} From 6832479251c818f9ae2332d09f39dd5febe5eb79 Mon Sep 17 00:00:00 2001 From: danagbemava Date: Thu, 10 Feb 2022 20:54:14 +0000 Subject: [PATCH 2/4] feat: add method to reload barcode information on internet error --- .../smooth_app/lib/data_models/continuous_scan_model.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/smooth_app/lib/data_models/continuous_scan_model.dart b/packages/smooth_app/lib/data_models/continuous_scan_model.dart index 1ba04d688c8..b2d79a42384 100644 --- a/packages/smooth_app/lib/data_models/continuous_scan_model.dart +++ b/packages/smooth_app/lib/data_models/continuous_scan_model.dart @@ -103,6 +103,11 @@ class ContinuousScanModel with ChangeNotifier { _addBarcode(code); } + Future retryBarcodeFetch(String barcode) async { + setBarcodeState(barcode, ScannedProductState.LOADING); + await _updateBarcode(barcode); + } + Future _addBarcode(final String barcode) async { final ScannedProductState? state = getBarcodeState(barcode); if (state == null) { From d08b018a400b8766fc19e691a8f57fed2cdca619 Mon Sep 17 00:00:00 2001 From: danagbemava Date: Thu, 10 Feb 2022 20:54:41 +0000 Subject: [PATCH 3/4] feat: update localizations and add retry button --- .../smooth_product_card_error.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/cards/product_cards/smooth_product_card_error.dart b/packages/smooth_app/lib/cards/product_cards/smooth_product_card_error.dart index 64eeaabe8bc..a75006eb72e 100644 --- a/packages/smooth_app/lib/cards/product_cards/smooth_product_card_error.dart +++ b/packages/smooth_app/lib/cards/product_cards/smooth_product_card_error.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:provider/provider.dart'; + +import 'package:smooth_app/data_models/continuous_scan_model.dart'; import 'package:smooth_app/pages/product/common/product_dialog_helper.dart'; /// Product Card when an exception is caught @@ -10,6 +13,8 @@ class SmoothProductCardError extends StatelessWidget { @override Widget build(BuildContext context) { + final AppLocalizations appLocalizations = AppLocalizations.of(context)!; + return Container( decoration: BoxDecoration( color: Theme.of(context).colorScheme.surface, @@ -30,7 +35,18 @@ class SmoothProductCardError extends StatelessWidget { height: 12.0, ), ProductDialogHelper.getErrorMessage( - AppLocalizations.of(context)!.product_internet_error, + appLocalizations.product_internet_error, + ), + const SizedBox( + height: 12.0, + ), + ElevatedButton( + onPressed: () async { + await context + .read() + .retryBarcodeFetch(barcode); + }, + child: Text(appLocalizations.retry_button_label), ), ], ), From d06f5df69ec17d75a7de32734503ab87306357d3 Mon Sep 17 00:00:00 2001 From: Daniel Agbemava Date: Fri, 11 Feb 2022 19:09:19 +0000 Subject: [PATCH 4/4] chore: make setBarcodeState private --- .../lib/data_models/continuous_scan_model.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/smooth_app/lib/data_models/continuous_scan_model.dart b/packages/smooth_app/lib/data_models/continuous_scan_model.dart index b2d79a42384..0722742a048 100644 --- a/packages/smooth_app/lib/data_models/continuous_scan_model.dart +++ b/packages/smooth_app/lib/data_models/continuous_scan_model.dart @@ -74,7 +74,7 @@ class ContinuousScanModel with ChangeNotifier { Future refreshProductList() async => _daoProductList.get(_productList); - void setBarcodeState( + void _setBarcodeState( final String barcode, final ScannedProductState state, ) { @@ -104,7 +104,7 @@ class ContinuousScanModel with ChangeNotifier { } Future retryBarcodeFetch(String barcode) async { - setBarcodeState(barcode, ScannedProductState.LOADING); + _setBarcodeState(barcode, ScannedProductState.LOADING); await _updateBarcode(barcode); } @@ -112,7 +112,7 @@ class ContinuousScanModel with ChangeNotifier { final ScannedProductState? state = getBarcodeState(barcode); if (state == null) { _barcodes.add(barcode); - setBarcodeState(barcode, ScannedProductState.LOADING); + _setBarcodeState(barcode, ScannedProductState.LOADING); _cacheOrLoadBarcode(barcode); return true; } @@ -164,10 +164,10 @@ class ContinuousScanModel with ChangeNotifier { _addProduct(fetchedProduct.product!, ScannedProductState.FOUND); return; case FetchedProductStatus.internetNotFound: - setBarcodeState(barcode, ScannedProductState.NOT_FOUND); + _setBarcodeState(barcode, ScannedProductState.NOT_FOUND); return; case FetchedProductStatus.internetError: - setBarcodeState(barcode, ScannedProductState.ERROR); + _setBarcodeState(barcode, ScannedProductState.ERROR); return; case FetchedProductStatus.userCancelled: // we do nothing @@ -184,10 +184,10 @@ class ContinuousScanModel with ChangeNotifier { _addProduct(fetchedProduct.product!, ScannedProductState.FOUND); return; case FetchedProductStatus.internetNotFound: - setBarcodeState(barcode, ScannedProductState.NOT_FOUND); + _setBarcodeState(barcode, ScannedProductState.NOT_FOUND); return; case FetchedProductStatus.internetError: - setBarcodeState(barcode, ScannedProductState.ERROR); + _setBarcodeState(barcode, ScannedProductState.ERROR); return; case FetchedProductStatus.userCancelled: // we do nothing @@ -205,7 +205,7 @@ class ContinuousScanModel with ChangeNotifier { await _daoProductList.push(productList, _latestFoundBarcode!); await _daoProductList.push(_history, _latestFoundBarcode!); } - setBarcodeState(product.barcode!, state); + _setBarcodeState(product.barcode!, state); } Future clearScanSession() async {