Showing
3 changed files
with
15 additions
and
9 deletions
| @@ -119,9 +119,11 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -119,9 +119,11 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | ||
| 119 | void _setupListeners() { | 119 | void _setupListeners() { |
| 120 | _barcodesSubscription = MobileScannerPlatform.instance.barcodesStream | 120 | _barcodesSubscription = MobileScannerPlatform.instance.barcodesStream |
| 121 | .listen((BarcodeCapture? barcode) { | 121 | .listen((BarcodeCapture? barcode) { |
| 122 | - if (!_barcodesController.isClosed && barcode != null) { | ||
| 123 | - _barcodesController.add(barcode); | 122 | + if (_barcodesController.isClosed || barcode == null) { |
| 123 | + return; | ||
| 124 | } | 124 | } |
| 125 | + | ||
| 126 | + _barcodesController.add(barcode); | ||
| 125 | }); | 127 | }); |
| 126 | 128 | ||
| 127 | _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream | 129 | _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream |
| @@ -113,7 +113,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -113,7 +113,9 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 113 | 113 | ||
| 114 | try { | 114 | try { |
| 115 | // Clear the existing barcodes. | 115 | // Clear the existing barcodes. |
| 116 | - _barcodesController.add(const BarcodeCapture()); | 116 | + if (!_barcodesController.isClosed) { |
| 117 | + _barcodesController.add(const BarcodeCapture()); | ||
| 118 | + } | ||
| 117 | 119 | ||
| 118 | // Listen for changes to the media track settings. | 120 | // Listen for changes to the media track settings. |
| 119 | _barcodeReader.setMediaTrackSettingsListener( | 121 | _barcodeReader.setMediaTrackSettingsListener( |
| @@ -187,13 +187,15 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -187,13 +187,15 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 187 | _reader as JSAny?, | 187 | _reader as JSAny?, |
| 188 | _reader?.videoElement as JSAny?, | 188 | _reader?.videoElement as JSAny?, |
| 189 | (Result? result, JSAny? error) { | 189 | (Result? result, JSAny? error) { |
| 190 | - if (!controller.isClosed && result != null) { | ||
| 191 | - controller.add( | ||
| 192 | - BarcodeCapture( | ||
| 193 | - barcodes: [result.toBarcode], | ||
| 194 | - ), | ||
| 195 | - ); | 190 | + if (controller.isClosed || result == null) { |
| 191 | + return; | ||
| 196 | } | 192 | } |
| 193 | + | ||
| 194 | + controller.add( | ||
| 195 | + BarcodeCapture( | ||
| 196 | + barcodes: [result.toBarcode], | ||
| 197 | + ), | ||
| 198 | + ); | ||
| 197 | }.toJS, | 199 | }.toJS, |
| 198 | ); | 200 | ); |
| 199 | }; | 201 | }; |
-
Please register or login to post a comment