Showing
1 changed file
with
10 additions
and
6 deletions
| @@ -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,8 +362,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -360,8 +362,9 @@ 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(); | ||
| 364 | - await MobileScannerPlatform.instance.stop(); | 365 | + if (_stop()) { |
| 366 | + await MobileScannerPlatform.instance.stop(); | ||
| 367 | + } | ||
| 365 | } | 368 | } |
| 366 | 369 | ||
| 367 | /// Pause the camera. | 370 | /// Pause the camera. |
| @@ -371,8 +374,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { | @@ -371,8 +374,9 @@ 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(); | ||
| 375 | - await MobileScannerPlatform.instance.pause(); | 377 | + if (_stop()) { |
| 378 | + await MobileScannerPlatform.instance.pause(); | ||
| 379 | + } | ||
| 376 | } | 380 | } |
| 377 | 381 | ||
| 378 | /// Switch between the front and back camera. | 382 | /// Switch between the front and back camera. |
-
Please register or login to post a comment