Navaron Bracke

forward scan errors to the controller

@@ -124,14 +124,25 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -124,14 +124,25 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
124 } 124 }
125 125
126 void _setupListeners() { 126 void _setupListeners() {
127 - _barcodesSubscription = MobileScannerPlatform.instance.barcodesStream  
128 - .listen((BarcodeCapture? barcode) { 127 + _barcodesSubscription =
  128 + MobileScannerPlatform.instance.barcodesStream.listen(
  129 + (BarcodeCapture? barcode) {
129 if (_barcodesController.isClosed || barcode == null) { 130 if (_barcodesController.isClosed || barcode == null) {
130 return; 131 return;
131 } 132 }
132 133
133 _barcodesController.add(barcode); 134 _barcodesController.add(barcode);
134 - }); 135 + },
  136 + onError: (Object error) {
  137 + if (_barcodesController.isClosed) {
  138 + return;
  139 + }
  140 +
  141 + _barcodesController.addError(error);
  142 + },
  143 + // Errors are handled gracefully by forwarding them.
  144 + cancelOnError: false,
  145 + );
135 146
136 _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream 147 _torchStateSubscription = MobileScannerPlatform.instance.torchStateStream
137 .listen((TorchState torchState) { 148 .listen((TorchState torchState) {