Navaron Bracke

ensure no stale values are present when initialization fails

@@ -248,11 +248,17 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -248,11 +248,17 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
248 ); 248 );
249 } on MobileScannerException catch (error) { 249 } on MobileScannerException catch (error) {
250 // The initialization finished with an error. 250 // The initialization finished with an error.
  251 + // To avoid stale values, reset the output size,
  252 + // torch state and zoom scale to the defaults.
251 if (!_isDisposed) { 253 if (!_isDisposed) {
252 value = value.copyWith( 254 value = value.copyWith(
253 cameraDirection: facing, 255 cameraDirection: facing,
254 isInitialized: true, 256 isInitialized: true,
  257 + isRunning: false,
255 error: error, 258 error: error,
  259 + size: Size.zero,
  260 + torchState: TorchState.unavailable,
  261 + zoomScale: 1.0,
256 ); 262 );
257 } 263 }
258 } 264 }