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), ), ], ), 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..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, ) { @@ -103,11 +103,16 @@ 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) { _barcodes.add(barcode); - setBarcodeState(barcode, ScannedProductState.LOADING); + _setBarcodeState(barcode, ScannedProductState.LOADING); _cacheOrLoadBarcode(barcode); return true; } @@ -159,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 @@ -179,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 @@ -200,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 { 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" +}