From 5c0d5e0c8aee8e7b4af4f1d35b773b0f2731400e Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 15 Jan 2025 23:43:49 +0100 Subject: [PATCH] imp: add code check for stop --- lib/src/mobile_scanner_controller.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/src/mobile_scanner_controller.dart b/lib/src/mobile_scanner_controller.dart index 479e4db4..742b109e 100644 --- a/lib/src/mobile_scanner_controller.dart +++ b/lib/src/mobile_scanner_controller.dart @@ -183,13 +183,14 @@ class MobileScannerController extends ValueNotifier { } } - void _stop() { + /// Returns false if stop is called but not necessary, otherwise true is returned. + bool _stop() { // Do nothing if not initialized or already stopped. // On the web, the permission popup triggers a lifecycle change from resumed to inactive, // due to the permission popup gaining focus. // This would 'stop' the camera while it is not ready yet. if (!value.isInitialized || !value.isRunning || _isDisposed) { - return; + return false; } _disposeListeners(); @@ -205,6 +206,7 @@ class MobileScannerController extends ValueNotifier { ? TorchState.unavailable : TorchState.off, ); + return true; } /// Analyze an image file. @@ -360,8 +362,9 @@ class MobileScannerController extends ValueNotifier { /// /// Does nothing if the camera is already stopped. Future stop() async { - _stop(); - await MobileScannerPlatform.instance.stop(); + if (_stop()) { + await MobileScannerPlatform.instance.stop(); + } } /// Pause the camera. @@ -371,8 +374,9 @@ class MobileScannerController extends ValueNotifier { /// /// Does nothing if the camera is already paused or stopped. Future pause() async { - _stop(); - await MobileScannerPlatform.instance.pause(); + if (_stop()) { + await MobileScannerPlatform.instance.pause(); + } } /// Switch between the front and back camera.