From eea9038d5ca3514ae9f2a9b36b2e2f7316f07de2 Mon Sep 17 00:00:00 2001 From: NIK Date: Wed, 6 Sep 2023 09:42:05 +0800 Subject: [PATCH] filtering barcodes list only applies of more than 1 is scanned --- lib/ui/home_page/components/scanner_widget.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ui/home_page/components/scanner_widget.dart b/lib/ui/home_page/components/scanner_widget.dart index d90f1daa..53168730 100644 --- a/lib/ui/home_page/components/scanner_widget.dart +++ b/lib/ui/home_page/components/scanner_widget.dart @@ -85,15 +85,15 @@ class _ScannerWidgetState extends State { torchEnabled: false, ), onDetect: (capture) { - final List barcodes = capture.barcodes; - final barcode = barcodes.firstOrNull; + final List 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().add( ErrorHandlerEvent.onError( @@ -104,7 +104,7 @@ class _ScannerWidgetState extends State { ), ); } else { - final String code = barcode.rawValue!; + final String code = barcodes.first!.rawValue!; LogHelper.d('Barcode found! $code'); hideScanner(); context.read().add(HomeEvent.onQRCodeScanned(code));