Navaron Bracke

fix bug with permissions on Android

@@ -223,12 +223,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -223,12 +223,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
223 } 223 }
224 224
225 /// Start scanning for barcodes. 225 /// Start scanning for barcodes.
226 - /// Upon calling this method, the necessary camera permission will be requested.  
227 /// 226 ///
228 /// The [cameraDirection] can be used to specify the camera direction. 227 /// The [cameraDirection] can be used to specify the camera direction.
229 /// If this is null, this defaults to the [facing] value. 228 /// If this is null, this defaults to the [facing] value.
230 /// 229 ///
231 /// Does nothing if the camera is already running. 230 /// Does nothing if the camera is already running.
  231 + /// Upon calling this method, the necessary camera permission will be requested.
  232 + ///
  233 + /// If the permission is denied on iOS, MacOS or Web, there is no way to request it again.
232 Future<void> start({CameraFacing? cameraDirection}) async { 234 Future<void> start({CameraFacing? cameraDirection}) async {
233 if (_isDisposed) { 235 if (_isDisposed) {
234 throw const MobileScannerException( 236 throw const MobileScannerException(
@@ -240,6 +242,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -240,6 +242,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
240 ); 242 );
241 } 243 }
242 244
  245 + // Permission was denied, do nothing.
  246 + // When the controller is stopped,
  247 + // the error is reset so the permission can be requested again if possible.
  248 + if (value.error?.errorCode == MobileScannerErrorCode.permissionDenied) {
  249 + return;
  250 + }
  251 +
243 // Do nothing if the camera is already running. 252 // Do nothing if the camera is already running.
244 if (value.isRunning) { 253 if (value.isRunning) {
245 return; 254 return;