Skip to content

Commit

Permalink
filtering barcodes list
Browse files Browse the repository at this point in the history
only applies of more than 1 is scanned
  • Loading branch information
n13 committed Sep 6, 2023
1 parent ae98dc1 commit eea9038
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ui/home_page/components/scanner_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class _ScannerWidgetState extends State<ScannerWidget> {
torchEnabled: false,
),
onDetect: (capture) {
final List<Barcode> barcodes = capture.barcodes;
final barcode = barcodes.firstOrNull;
final List<Barcode> barcodes =
capture.barcodes.where((element) => element.rawValue != null).toList();

// TODO(NIK): What this should do is - for each QR code, determine whether or not
// we can handle it - skip if we can't handle it (example: non-ESR URL)
// Take the first one we can handle, and pass it up the block and close the scanner
// If we can't handle any, keep scanning.

if (barcode == null || barcode.rawValue == null || barcode.isBlank == true) {
if (barcodes.isEmpty) {
LogHelper.d('Failed to scan Barcode');
context.read<ErrorHandlerBloc>().add(
ErrorHandlerEvent.onError(
Expand All @@ -104,7 +104,7 @@ class _ScannerWidgetState extends State<ScannerWidget> {
),
);
} else {
final String code = barcode.rawValue!;
final String code = barcodes.first!.rawValue!;
LogHelper.d('Barcode found! $code');
hideScanner();
context.read<HomeBloc>().add(HomeEvent.onQRCodeScanned(code));
Expand Down

0 comments on commit eea9038

Please sign in to comment.