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> { @@ -175,9 +175,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
175 } 175 }
176 176
177 /// Reset the zoom scale of the camera. 177 /// Reset the zoom scale of the camera.
  178 + ///
  179 + /// Does nothing if the camera is not running.
178 Future<void> resetZoomScale() async { 180 Future<void> resetZoomScale() async {
179 _throwIfNotInitialized(); 181 _throwIfNotInitialized();
180 182
  183 + if (!value.isRunning) {
  184 + return;
  185 + }
  186 +
181 // When the platform has updated the zoom scale, 187 // When the platform has updated the zoom scale,
182 // it will send an update through the zoom scale state event stream. 188 // it will send an update through the zoom scale state event stream.
183 await MobileScannerPlatform.instance.resetZoomScale(); 189 await MobileScannerPlatform.instance.resetZoomScale();
@@ -189,9 +195,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -189,9 +195,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
189 /// 195 ///
190 /// If the [zoomScale] is out of range, 196 /// If the [zoomScale] is out of range,
191 /// it is adjusted to fit within the allowed range. 197 /// it is adjusted to fit within the allowed range.
  198 + ///
  199 + /// Does nothing if the camera is not running.
192 Future<void> setZoomScale(double zoomScale) async { 200 Future<void> setZoomScale(double zoomScale) async {
193 _throwIfNotInitialized(); 201 _throwIfNotInitialized();
194 202
  203 + if (!value.isRunning) {
  204 + return;
  205 + }
  206 +
195 final double clampedZoomScale = zoomScale.clamp(0.0, 1.0); 207 final double clampedZoomScale = zoomScale.clamp(0.0, 1.0);
196 208
197 // Update the zoom scale state to the new state. 209 // Update the zoom scale state to the new state.
@@ -313,10 +325,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -313,10 +325,15 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
313 325
314 /// Switches the flashlight on or off. 326 /// Switches the flashlight on or off.
315 /// 327 ///
316 - /// Does nothing if the device has no torch. 328 + /// Does nothing if the device has no torch,
  329 + /// or if the camera is not running.
317 Future<void> toggleTorch() async { 330 Future<void> toggleTorch() async {
318 _throwIfNotInitialized(); 331 _throwIfNotInitialized();
319 332
  333 + if (!value.isRunning) {
  334 + return;
  335 + }
  336 +
320 final TorchState torchState = value.torchState; 337 final TorchState torchState = value.torchState;
321 338
322 if (torchState == TorchState.unavailable) { 339 if (torchState == TorchState.unavailable) {