Navaron Bracke

do nothing in start/stop if already started/stopped

... ... @@ -205,6 +205,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
///
/// The [cameraDirection] can be used to specify the camera direction.
/// If this is null, this defaults to the [facing] value.
///
/// Does nothing if the camera is already running.
Future<void> start({CameraFacing? cameraDirection}) async {
if (_isDisposed) {
throw const MobileScannerException(
... ... @@ -216,6 +218,11 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
);
}
// Do nothing if the camera is already running.
if (value.isRunning) {
return;
}
final CameraFacing effectiveDirection = cameraDirection ?? facing;
final StartOptions options = StartOptions(
... ... @@ -267,11 +274,18 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
/// Stop the camera.
///
/// After calling this method, the camera can be restarted using [start].
///
/// Does nothing if the camera is already stopped.
Future<void> stop() async {
_disposeListeners();
_throwIfNotInitialized();
// Do nothing if already stopped.
if (!value.isRunning) {
return;
}
_disposeListeners();
// After the camera stopped, set the torch state to off,
// as the torch state callback is never called when the camera is stopped.
value = value.copyWith(
... ...