Julian Steenbakker

imp: add code check for stop

@@ -183,13 +183,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -183,13 +183,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
183 } 183 }
184 } 184 }
185 185
186 - void _stop() { 186 + /// Returns false if stop is called but not necessary, otherwise true is returned.
  187 + bool _stop() {
187 // Do nothing if not initialized or already stopped. 188 // Do nothing if not initialized or already stopped.
188 // On the web, the permission popup triggers a lifecycle change from resumed to inactive, 189 // On the web, the permission popup triggers a lifecycle change from resumed to inactive,
189 // due to the permission popup gaining focus. 190 // due to the permission popup gaining focus.
190 // This would 'stop' the camera while it is not ready yet. 191 // This would 'stop' the camera while it is not ready yet.
191 if (!value.isInitialized || !value.isRunning || _isDisposed) { 192 if (!value.isInitialized || !value.isRunning || _isDisposed) {
192 - return; 193 + return false;
193 } 194 }
194 195
195 _disposeListeners(); 196 _disposeListeners();
@@ -205,6 +206,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -205,6 +206,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
205 ? TorchState.unavailable 206 ? TorchState.unavailable
206 : TorchState.off, 207 : TorchState.off,
207 ); 208 );
  209 + return true;
208 } 210 }
209 211
210 /// Analyze an image file. 212 /// Analyze an image file.
@@ -360,9 +362,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -360,9 +362,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
360 /// 362 ///
361 /// Does nothing if the camera is already stopped. 363 /// Does nothing if the camera is already stopped.
362 Future<void> stop() async { 364 Future<void> stop() async {
363 - _stop(); 365 + if (_stop()) {
364 await MobileScannerPlatform.instance.stop(); 366 await MobileScannerPlatform.instance.stop();
365 } 367 }
  368 + }
366 369
367 /// Pause the camera. 370 /// Pause the camera.
368 /// 371 ///
@@ -371,9 +374,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -371,9 +374,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
371 /// 374 ///
372 /// Does nothing if the camera is already paused or stopped. 375 /// Does nothing if the camera is already paused or stopped.
373 Future<void> pause() async { 376 Future<void> pause() async {
374 - _stop(); 377 + if (_stop()) {
375 await MobileScannerPlatform.instance.pause(); 378 await MobileScannerPlatform.instance.pause();
376 } 379 }
  380 + }
377 381
378 /// Switch between the front and back camera. 382 /// Switch between the front and back camera.
379 /// 383 ///