Showing
3 changed files
with
30 additions
and
2 deletions
| @@ -322,6 +322,15 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -322,6 +322,15 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 322 | 322 | ||
| 323 | _barcodesController.add(barcode); | 323 | _barcodesController.add(barcode); |
| 324 | }, | 324 | }, |
| 325 | + onError: (Object error) { | ||
| 326 | + if (_barcodesController.isClosed) { | ||
| 327 | + return; | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + _barcodesController.addError(error); | ||
| 331 | + }, | ||
| 332 | + // Errors are handled gracefully by forwarding them. | ||
| 333 | + cancelOnError: false, | ||
| 325 | ); | 334 | ); |
| 326 | 335 | ||
| 327 | final bool hasTorch = await _barcodeReader?.hasTorch() ?? false; | 336 | final bool hasTorch = await _barcodeReader?.hasTorch() ?? false; |
| @@ -3,6 +3,7 @@ import 'dart:js_interop'; | @@ -3,6 +3,7 @@ import 'dart:js_interop'; | ||
| 3 | import 'dart:ui'; | 3 | import 'dart:ui'; |
| 4 | 4 | ||
| 5 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; | 5 | import 'package:mobile_scanner/src/enums/barcode_format.dart'; |
| 6 | +import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; | ||
| 6 | import 'package:mobile_scanner/src/objects/barcode_capture.dart'; | 7 | import 'package:mobile_scanner/src/objects/barcode_capture.dart'; |
| 7 | import 'package:mobile_scanner/src/objects/start_options.dart'; | 8 | import 'package:mobile_scanner/src/objects/start_options.dart'; |
| 8 | import 'package:mobile_scanner/src/web/barcode_reader.dart'; | 9 | import 'package:mobile_scanner/src/web/barcode_reader.dart'; |
| @@ -10,6 +11,7 @@ import 'package:mobile_scanner/src/web/javascript_map.dart'; | @@ -10,6 +11,7 @@ import 'package:mobile_scanner/src/web/javascript_map.dart'; | ||
| 10 | import 'package:mobile_scanner/src/web/media_track_constraints_delegate.dart'; | 11 | import 'package:mobile_scanner/src/web/media_track_constraints_delegate.dart'; |
| 11 | import 'package:mobile_scanner/src/web/zxing/result.dart'; | 12 | import 'package:mobile_scanner/src/web/zxing/result.dart'; |
| 12 | import 'package:mobile_scanner/src/web/zxing/zxing_browser_multi_format_reader.dart'; | 13 | import 'package:mobile_scanner/src/web/zxing/zxing_browser_multi_format_reader.dart'; |
| 14 | +import 'package:mobile_scanner/src/web/zxing/zxing_exception.dart'; | ||
| 13 | import 'package:web/web.dart' as web; | 15 | import 'package:web/web.dart' as web; |
| 14 | 16 | ||
| 15 | /// A barcode reader implementation that uses the ZXing library. | 17 | /// A barcode reader implementation that uses the ZXing library. |
| @@ -98,16 +100,23 @@ final class ZXingBarcodeReader extends BarcodeReader { | @@ -98,16 +100,23 @@ final class ZXingBarcodeReader extends BarcodeReader { | ||
| 98 | _reader?.decodeContinuously.callAsFunction( | 100 | _reader?.decodeContinuously.callAsFunction( |
| 99 | _reader, | 101 | _reader, |
| 100 | _reader?.videoElement, | 102 | _reader?.videoElement, |
| 101 | - (Result? result, JSAny? error) { | ||
| 102 | - if (controller.isClosed || result == null) { | 103 | + (Result? result, ZXingException? error) { |
| 104 | + if (controller.isClosed) { | ||
| 103 | return; | 105 | return; |
| 104 | } | 106 | } |
| 105 | 107 | ||
| 108 | + if (error != null) { | ||
| 109 | + controller.addError(MobileScannerBarcodeException(error.message)); | ||
| 110 | + return; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + if (result != null) { | ||
| 106 | controller.add( | 114 | controller.add( |
| 107 | BarcodeCapture( | 115 | BarcodeCapture( |
| 108 | barcodes: [result.toBarcode], | 116 | barcodes: [result.toBarcode], |
| 109 | ), | 117 | ), |
| 110 | ); | 118 | ); |
| 119 | + } | ||
| 111 | }.toJS, | 120 | }.toJS, |
| 112 | ); | 121 | ); |
| 113 | }; | 122 | }; |
lib/src/web/zxing/zxing_exception.dart
0 → 100644
| 1 | +import 'dart:js_interop'; | ||
| 2 | + | ||
| 3 | +/// The JS static interop class for the Result class in the ZXing library. | ||
| 4 | +/// | ||
| 5 | +/// See also: https://github.com/zxing-js/library/blob/master/src/core/Exception.ts | ||
| 6 | +@JS('ZXing.Exception') | ||
| 7 | +extension type ZXingException._(JSObject _) implements JSObject { | ||
| 8 | + /// The error message of the exception, if any. | ||
| 9 | + external String? get message; | ||
| 10 | +} |
-
Please register or login to post a comment