Navaron Bracke

let web throw when start is called once the barcode reader is set

@@ -280,6 +280,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -280,6 +280,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
280 ); 280 );
281 } 281 }
282 } on MobileScannerException catch (error) { 282 } on MobileScannerException catch (error) {
  283 + // TODO: if the error code is `controllerAlreadyInitialized` ignore the error
  284 + // TODO: update the error reporting from the native side to report proper error codes.
  285 +
283 // The initialization finished with an error. 286 // The initialization finished with an error.
284 // To avoid stale values, reset the output size, 287 // To avoid stale values, reset the output size,
285 // torch state and zoom scale to the defaults. 288 // torch state and zoom scale to the defaults.
@@ -253,6 +253,17 @@ class MobileScannerWeb extends MobileScannerPlatform { @@ -253,6 +253,17 @@ class MobileScannerWeb extends MobileScannerPlatform {
253 253
254 @override 254 @override
255 Future<MobileScannerViewAttributes> start(StartOptions startOptions) async { 255 Future<MobileScannerViewAttributes> start(StartOptions startOptions) async {
  256 + // TODO: ignore double starts in the controller.
  257 + if (_barcodeReader != null) {
  258 + throw const MobileScannerException(
  259 + errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
  260 + errorDetails: MobileScannerErrorDetails(
  261 + message:
  262 + 'The scanner was already started. Call stop() before calling start() again.',
  263 + ),
  264 + );
  265 + }
  266 +
256 _barcodeReader = ZXingBarcodeReader(); 267 _barcodeReader = ZXingBarcodeReader();
257 268
258 await _barcodeReader?.maybeLoadLibrary( 269 await _barcodeReader?.maybeLoadLibrary(
@@ -260,6 +271,7 @@ class MobileScannerWeb extends MobileScannerPlatform { @@ -260,6 +271,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
260 ); 271 );
261 272
262 if (_barcodeReader?.isScanning ?? false) { 273 if (_barcodeReader?.isScanning ?? false) {
  274 + // TODO: ignore double starts in the controller.
263 throw const MobileScannerException( 275 throw const MobileScannerException(
264 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized, 276 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
265 errorDetails: MobileScannerErrorDetails( 277 errorDetails: MobileScannerErrorDetails(