Skip to content

Commit 5c0d5e0

Browse files
imp: add code check for stop
1 parent 9f602a3 commit 5c0d5e0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/src/mobile_scanner_controller.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
183183
}
184184
}
185185

186-
void _stop() {
186+
/// Returns false if stop is called but not necessary, otherwise true is returned.
187+
bool _stop() {
187188
// Do nothing if not initialized or already stopped.
188189
// On the web, the permission popup triggers a lifecycle change from resumed to inactive,
189190
// due to the permission popup gaining focus.
190191
// This would 'stop' the camera while it is not ready yet.
191192
if (!value.isInitialized || !value.isRunning || _isDisposed) {
192-
return;
193+
return false;
193194
}
194195

195196
_disposeListeners();
@@ -205,6 +206,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
205206
? TorchState.unavailable
206207
: TorchState.off,
207208
);
209+
return true;
208210
}
209211

210212
/// Analyze an image file.
@@ -360,8 +362,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
360362
///
361363
/// Does nothing if the camera is already stopped.
362364
Future<void> stop() async {
363-
_stop();
364-
await MobileScannerPlatform.instance.stop();
365+
if (_stop()) {
366+
await MobileScannerPlatform.instance.stop();
367+
}
365368
}
366369

367370
/// Pause the camera.
@@ -371,8 +374,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
371374
///
372375
/// Does nothing if the camera is already paused or stopped.
373376
Future<void> pause() async {
374-
_stop();
375-
await MobileScannerPlatform.instance.pause();
377+
if (_stop()) {
378+
await MobileScannerPlatform.instance.pause();
379+
}
376380
}
377381

378382
/// Switch between the front and back camera.

0 commit comments

Comments
 (0)