@@ -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
188
// Do nothing if not initialized or already stopped.
188
189
// On the web, the permission popup triggers a lifecycle change from resumed to inactive,
189
190
// due to the permission popup gaining focus.
190
191
// This would 'stop' the camera while it is not ready yet.
191
192
if (! value.isInitialized || ! value.isRunning || _isDisposed) {
192
- return ;
193
+ return false ;
193
194
}
194
195
195
196
_disposeListeners ();
@@ -205,6 +206,7 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
205
206
? TorchState .unavailable
206
207
: TorchState .off,
207
208
);
209
+ return true ;
208
210
}
209
211
210
212
/// Analyze an image file.
@@ -360,8 +362,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
360
362
///
361
363
/// Does nothing if the camera is already stopped.
362
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
370
/// Pause the camera.
@@ -371,8 +374,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
371
374
///
372
375
/// Does nothing if the camera is already paused or stopped.
373
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
382
/// Switch between the front and back camera.
0 commit comments