Navaron Bracke

don't update the zoom scale or torch state if the camer is not running

... ... @@ -175,9 +175,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
}
/// Reset the zoom scale of the camera.
///
/// Does nothing if the camera is not running.
Future<void> resetZoomScale() async {
_throwIfNotInitialized();
if (!value.isRunning) {
return;
}
// When the platform has updated the zoom scale,
// it will send an update through the zoom scale state event stream.
await MobileScannerPlatform.instance.resetZoomScale();
... ... @@ -189,9 +195,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
///
/// If the [zoomScale] is out of range,
/// it is adjusted to fit within the allowed range.
///
/// Does nothing if the camera is not running.
Future<void> setZoomScale(double zoomScale) async {
_throwIfNotInitialized();
if (!value.isRunning) {
return;
}
final double clampedZoomScale = zoomScale.clamp(0.0, 1.0);
// Update the zoom scale state to the new state.
... ... @@ -313,10 +325,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
/// Switches the flashlight on or off.
///
/// Does nothing if the device has no torch.
/// Does nothing if the device has no torch,
/// or if the camera is not running.
Future<void> toggleTorch() async {
_throwIfNotInitialized();
if (!value.isRunning) {
return;
}
final TorchState torchState = value.torchState;
if (torchState == TorchState.unavailable) {
... ...