From e0eef28092941d65862352fea96b950cfbad8452 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Thu, 27 Apr 2023 13:30:37 +0400 Subject: [PATCH] fixed multiple code scan issue from image path --- lib/src/ui/reader_widget.dart | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index 914dc1d..a1267f3 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -458,19 +458,30 @@ class _ReaderWidgetState extends State final XFile? file = await ImagePicker().pickImage(source: ImageSource.gallery); if (file != null) { - final Code result = await zx.readBarcodeImagePath( - file, - params: DecodeParams( - format: widget.codeFormat, - tryHarder: widget.tryHarder, - tryInverted: widget.tryInverted, - isMultiScan: widget.isMultiScan, - ), + final DecodeParams params = DecodeParams( + format: widget.codeFormat, + tryHarder: widget.tryHarder, + tryInverted: widget.tryInverted, + isMultiScan: widget.isMultiScan, ); - if (result.isValid) { - widget.onScan?.call(result); + if (widget.isMultiScan) { + final Codes result = + await zx.readBarcodesImagePath(file, params: params); + if (result.codes.isNotEmpty) { + results = result; + widget.onMultiScan?.call(result); + setState(() {}); + } else { + results = Codes(); + widget.onMultiScanFailure?.call(result); + } } else { - widget.onScanFailure?.call(result); + final Code result = await zx.readBarcodeImagePath(file, params: params); + if (result.isValid) { + widget.onScan?.call(result); + } else { + widget.onScanFailure?.call(result); + } } } }