Navaron Bracke

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

... ... @@ -280,6 +280,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
);
}
} on MobileScannerException catch (error) {
// TODO: if the error code is `controllerAlreadyInitialized` ignore the error
// TODO: update the error reporting from the native side to report proper error codes.
// The initialization finished with an error.
// To avoid stale values, reset the output size,
// torch state and zoom scale to the defaults.
... ...
... ... @@ -253,6 +253,17 @@ class MobileScannerWeb extends MobileScannerPlatform {
@override
Future<MobileScannerViewAttributes> start(StartOptions startOptions) async {
// TODO: ignore double starts in the controller.
if (_barcodeReader != null) {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
errorDetails: MobileScannerErrorDetails(
message:
'The scanner was already started. Call stop() before calling start() again.',
),
);
}
_barcodeReader = ZXingBarcodeReader();
await _barcodeReader?.maybeLoadLibrary(
... ... @@ -260,6 +271,7 @@ class MobileScannerWeb extends MobileScannerPlatform {
);
if (_barcodeReader?.isScanning ?? false) {
// TODO: ignore double starts in the controller.
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
errorDetails: MobileScannerErrorDetails(
... ...