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 378554191ca..49603dd3623 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 @@ -8,9 +8,13 @@ import 'package:smooth_app/pages/product/common/product_dialog_helper.dart'; /// Product Card when an exception is caught class SmoothProductCardError extends StatelessWidget { - const SmoothProductCardError({required this.barcode}); + const SmoothProductCardError({ + required this.barcode, + required this.errorType, + }); final String barcode; + final ScannedProductState errorType; @override Widget build(BuildContext context) { @@ -46,7 +50,10 @@ class SmoothProductCardError extends StatelessWidget { height: 12.0, ), ProductDialogHelper.getErrorMessage( - appLocalizations.product_internet_error, + _getErrorMessage( + errorType, + appLocalizations, + ), ), const SizedBox( height: 12.0, @@ -63,4 +70,18 @@ class SmoothProductCardError extends StatelessWidget { ), ); } + + String _getErrorMessage( + ScannedProductState errorType, + AppLocalizations appLocalizations, + ) { + switch (errorType) { + case ScannedProductState.ERROR_INVALID_CODE: + return appLocalizations.barcode_invalid_error; + case ScannedProductState.ERROR_INTERNET: + return appLocalizations.product_internet_error; + default: + return appLocalizations.error_occurred; + } + } } 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 60a093e5313..5f935c00b60 100644 --- a/packages/smooth_app/lib/data_models/continuous_scan_model.dart +++ b/packages/smooth_app/lib/data_models/continuous_scan_model.dart @@ -15,7 +15,8 @@ enum ScannedProductState { LOADING, THANKS, CACHED, - ERROR, + ERROR_INTERNET, + ERROR_INVALID_CODE, } class ContinuousScanModel with ChangeNotifier { @@ -193,7 +194,10 @@ class ContinuousScanModel with ChangeNotifier { _setBarcodeState(barcode, ScannedProductState.NOT_FOUND); return; case FetchedProductStatus.internetError: - _setBarcodeState(barcode, ScannedProductState.ERROR); + _setBarcodeState(barcode, ScannedProductState.ERROR_INTERNET); + return; + case FetchedProductStatus.codeInvalid: + _setBarcodeState(barcode, ScannedProductState.ERROR_INVALID_CODE); return; case FetchedProductStatus.userCancelled: // we do nothing @@ -213,7 +217,10 @@ class ContinuousScanModel with ChangeNotifier { _setBarcodeState(barcode, ScannedProductState.NOT_FOUND); return; case FetchedProductStatus.internetError: - _setBarcodeState(barcode, ScannedProductState.ERROR); + _setBarcodeState(barcode, ScannedProductState.ERROR_INTERNET); + return; + case FetchedProductStatus.codeInvalid: + _setBarcodeState(barcode, ScannedProductState.ERROR_INVALID_CODE); return; case FetchedProductStatus.userCancelled: // we do nothing diff --git a/packages/smooth_app/lib/data_models/fetched_product.dart b/packages/smooth_app/lib/data_models/fetched_product.dart index 1cd904fb8a9..e2c1c076fb0 100644 --- a/packages/smooth_app/lib/data_models/fetched_product.dart +++ b/packages/smooth_app/lib/data_models/fetched_product.dart @@ -6,6 +6,7 @@ enum FetchedProductStatus { internetNotFound, internetError, userCancelled, + codeInvalid, // TODO(monsieurtanuki): time-out } diff --git a/packages/smooth_app/lib/database/barcode_product_query.dart b/packages/smooth_app/lib/database/barcode_product_query.dart index 89ab65fb933..5e9ebeb62f8 100644 --- a/packages/smooth_app/lib/database/barcode_product_query.dart +++ b/packages/smooth_app/lib/database/barcode_product_query.dart @@ -36,6 +36,10 @@ class BarcodeProductQuery { return FetchedProduct(product); } } + if (barcode.trim().isNotEmpty && + (result.barcode == null || result.barcode!.isEmpty)) { + return FetchedProduct.error(FetchedProductStatus.codeInvalid); + } return FetchedProduct.error(FetchedProductStatus.internetNotFound); } } diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 2264a49a09e..be9f53507bb 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -1300,6 +1300,7 @@ } } }, + "barcode_invalid_error": "Invalid barcode", "basic_details_add_success": "Basic details added succesfully", "basic_details_add_error": "Unable to add basic details. Please try again after some time", "@basic_details_add_error": { diff --git a/packages/smooth_app/lib/pages/product/common/product_dialog_helper.dart b/packages/smooth_app/lib/pages/product/common/product_dialog_helper.dart index 05cabf8382d..f1bf2f61c01 100644 --- a/packages/smooth_app/lib/pages/product/common/product_dialog_helper.dart +++ b/packages/smooth_app/lib/pages/product/common/product_dialog_helper.dart @@ -99,6 +99,9 @@ class ProductDialogHelper { case FetchedProductStatus.internetNotFound: _openProductNotFoundDialog(); return; + case FetchedProductStatus.codeInvalid: + _openErrorMessage(appLocalizations.barcode_invalid_error); + return; } } } diff --git a/packages/smooth_app/lib/widgets/smooth_product_carousel.dart b/packages/smooth_app/lib/widgets/smooth_product_carousel.dart index c5c71716cf2..20dcdb06567 100644 --- a/packages/smooth_app/lib/widgets/smooth_product_carousel.dart +++ b/packages/smooth_app/lib/widgets/smooth_product_carousel.dart @@ -168,8 +168,16 @@ class _SmoothProductCarouselState extends State { ); case ScannedProductState.THANKS: return const SmoothProductCardThanks(); - case ScannedProductState.ERROR: - return SmoothProductCardError(barcode: barcode); + case ScannedProductState.ERROR_INTERNET: + return SmoothProductCardError( + barcode: barcode, + errorType: ScannedProductState.ERROR_INTERNET, + ); + case ScannedProductState.ERROR_INVALID_CODE: + return SmoothProductCardError( + barcode: barcode, + errorType: ScannedProductState.ERROR_INVALID_CODE, + ); } } }