Navaron Bracke

return if switchCameras() would not do anything

@@ -317,9 +317,20 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -317,9 +317,20 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
317 } 317 }
318 318
319 /// Switch between the front and back camera. 319 /// Switch between the front and back camera.
  320 + ///
  321 + /// Does nothing if the device has less than 2 cameras.
320 Future<void> switchCamera() async { 322 Future<void> switchCamera() async {
321 _throwIfNotInitialized(); 323 _throwIfNotInitialized();
322 324
  325 + final int? availableCameras = value.availableCameras;
  326 +
  327 + // Do nothing if the amount of cameras is less than 2 cameras.
  328 + // If the the current platform does not provide the amount of cameras,
  329 + // continue anyway.
  330 + if (availableCameras != null && availableCameras < 2) {
  331 + return;
  332 + }
  333 +
323 await stop(); 334 await stop();
324 335
325 final CameraFacing cameraDirection = value.cameraDirection; 336 final CameraFacing cameraDirection = value.cameraDirection;