Navaron Bracke

throw in zoom scale methods if not initialized

@@ -161,6 +161,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -161,6 +161,10 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
161 161
162 /// Reset the zoom scale of the camera. 162 /// Reset the zoom scale of the camera.
163 Future<void> resetZoomScale() async { 163 Future<void> resetZoomScale() async {
  164 + _throwIfNotInitialized();
  165 +
  166 + // When the platform has updated the zoom scale,
  167 + // it will send an update through the zoom scale state event stream.
164 await MobileScannerPlatform.instance.resetZoomScale(); 168 await MobileScannerPlatform.instance.resetZoomScale();
165 } 169 }
166 170
@@ -171,8 +175,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -171,8 +175,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
171 /// If the [zoomScale] is out of range, 175 /// If the [zoomScale] is out of range,
172 /// it is adjusted to fit within the allowed range. 176 /// it is adjusted to fit within the allowed range.
173 Future<void> setZoomScale(double zoomScale) async { 177 Future<void> setZoomScale(double zoomScale) async {
  178 + _throwIfNotInitialized();
  179 +
174 final double clampedZoomScale = zoomScale.clamp(0.0, 1.0); 180 final double clampedZoomScale = zoomScale.clamp(0.0, 1.0);
175 181
  182 + // Update the zoom scale state to the new state.
  183 + // When the platform has updated the zoom scale,
  184 + // it will send an update through the zoom scale state event stream.
176 await MobileScannerPlatform.instance.setZoomScale(clampedZoomScale); 185 await MobileScannerPlatform.instance.setZoomScale(clampedZoomScale);
177 } 186 }
178 187
@@ -253,8 +262,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -253,8 +262,6 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
253 /// Switches the flashlight on or off. 262 /// Switches the flashlight on or off.
254 /// 263 ///
255 /// Does nothing if the device has no torch. 264 /// Does nothing if the device has no torch.
256 - ///  
257 - /// Throws if the controller was not initialized.  
258 Future<void> toggleTorch() async { 265 Future<void> toggleTorch() async {
259 final bool hasTorch; 266 final bool hasTorch;
260 267