Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1427 scanning invalid code #2336

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}
}
13 changes: 10 additions & 3 deletions packages/smooth_app/lib/data_models/continuous_scan_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum ScannedProductState {
LOADING,
THANKS,
CACHED,
ERROR,
ERROR_INTERNET,
ERROR_INVALID_CODE,
}

class ContinuousScanModel with ChangeNotifier {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/smooth_app/lib/data_models/fetched_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum FetchedProductStatus {
internetNotFound,
internetError,
userCancelled,
codeInvalid,
// TODO(monsieurtanuki): time-out
}

Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/database/barcode_product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class ProductDialogHelper {
case FetchedProductStatus.internetNotFound:
_openProductNotFoundDialog();
return;
case FetchedProductStatus.codeInvalid:
_openErrorMessage(appLocalizations.barcode_invalid_error);
return;
}
}
}
12 changes: 10 additions & 2 deletions packages/smooth_app/lib/widgets/smooth_product_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ class _SmoothProductCarouselState extends State<SmoothProductCarousel> {
);
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,
);
}
}
}
Expand Down