forked from openfoodfacts/smooth-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prices - barcode reader for additional products (openfoodfacts#…
…5381) New file: * `price_scan_page.dart`: Page showing the camera feed and decoding the first barcode, for Prices. Impacted files: * `app_en.arb`: added 1 "barcode reader" label * `app_fr.arb`: added 1 "barcode reader" label * `camera_scan_page.dart`: minor refactoring * `price_product_search_page.dart`: added a FAB towards the new barcode reader page
- Loading branch information
1 parent
2a08ab4
commit 35a4ab0
Showing
5 changed files
with
143 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:matomo_tracker/matomo_tracker.dart'; | ||
import 'package:smooth_app/helpers/analytics_helper.dart'; | ||
import 'package:smooth_app/helpers/camera_helper.dart'; | ||
import 'package:smooth_app/helpers/global_vars.dart'; | ||
import 'package:smooth_app/helpers/haptic_feedback_helper.dart'; | ||
import 'package:smooth_app/pages/scan/camera_scan_page.dart'; | ||
import 'package:smooth_app/widgets/smooth_scaffold.dart'; | ||
|
||
/// Page showing the camera feed and decoding the first barcode, for Prices. | ||
class PriceScanPage extends StatefulWidget { | ||
const PriceScanPage(); | ||
|
||
@override | ||
State<PriceScanPage> createState() => _PriceScanPageState(); | ||
} | ||
|
||
class _PriceScanPageState extends State<PriceScanPage> | ||
with TraceableClientMixin { | ||
// Mutual exclusion needed: we typically receive several times the same | ||
// barcode and the `pop` would be called several times and cause an error like | ||
// `Failed assertion: line 5277 pos 12: '!_debugLocked': is not true.` | ||
bool _mutex = false; | ||
|
||
@override | ||
String get actionName => | ||
'Opened ${GlobalVars.barcodeScanner.getType()}_page for price'; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final AppLocalizations appLocalizations = AppLocalizations.of(context); | ||
return SmoothScaffold( | ||
body: GlobalVars.barcodeScanner.getScanner( | ||
onScan: (final String barcode) async { | ||
if (_mutex) { | ||
return false; | ||
} | ||
_mutex = true; | ||
Navigator.of(context).pop(barcode); | ||
return true; | ||
}, | ||
hapticFeedback: () => SmoothHapticFeedback.click(), | ||
onCameraFlashError: CameraScannerPage.onCameraFlashError, | ||
trackCustomEvent: AnalyticsHelper.trackCustomEvent, | ||
hasMoreThanOneCamera: CameraHelper.hasMoreThanOneCamera, | ||
toggleCameraModeTooltip: appLocalizations.camera_toggle_camera, | ||
toggleFlashModeTooltip: appLocalizations.camera_toggle_flash, | ||
contentPadding: null, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters