Navaron Bracke

add hasCameraPermission getter

@@ -60,7 +60,7 @@ class _BarcodeScannerWithControllerState @@ -60,7 +60,7 @@ class _BarcodeScannerWithControllerState
60 60
61 @override 61 @override
62 void didChangeAppLifecycleState(AppLifecycleState state) { 62 void didChangeAppLifecycleState(AppLifecycleState state) {
63 - if (!controller.value.isInitialized) { 63 + if (!controller.value.hasCameraPermission) {
64 return; 64 return;
65 } 65 }
66 66
@@ -281,8 +281,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -281,8 +281,7 @@ class _MobileScannerState extends State<MobileScanner>
281 281
282 @override 282 @override
283 void didChangeAppLifecycleState(AppLifecycleState state) { 283 void didChangeAppLifecycleState(AppLifecycleState state) {
284 - if (widget.controller != null) return;  
285 - if (!controller.value.isInitialized) { 284 + if (widget.controller != null || !controller.value.hasCameraPermission) {
286 return; 285 return;
287 } 286 }
288 287
1 import 'dart:ui'; 1 import 'dart:ui';
2 2
3 import 'package:mobile_scanner/src/enums/camera_facing.dart'; 3 import 'package:mobile_scanner/src/enums/camera_facing.dart';
  4 +import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart';
4 import 'package:mobile_scanner/src/enums/torch_state.dart'; 5 import 'package:mobile_scanner/src/enums/torch_state.dart';
5 import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; 6 import 'package:mobile_scanner/src/mobile_scanner_exception.dart';
6 7
@@ -43,7 +44,8 @@ class MobileScannerState { @@ -43,7 +44,8 @@ class MobileScannerState {
43 44
44 /// Whether the mobile scanner has initialized successfully. 45 /// Whether the mobile scanner has initialized successfully.
45 /// 46 ///
46 - /// This is `true` if the camera is ready to be used. 47 + /// This does not indicate that the camera permission was granted.
  48 + /// To check if the camera permission was granted, use [hasCameraPermission].
47 final bool isInitialized; 49 final bool isInitialized;
48 50
49 /// Whether the mobile scanner is currently running. 51 /// Whether the mobile scanner is currently running.
@@ -60,6 +62,12 @@ class MobileScannerState { @@ -60,6 +62,12 @@ class MobileScannerState {
60 /// The current zoom scale of the camera. 62 /// The current zoom scale of the camera.
61 final double zoomScale; 63 final double zoomScale;
62 64
  65 + /// Whether permission to access the camera was granted.
  66 + bool get hasCameraPermission {
  67 + return isInitialized &&
  68 + error?.errorCode != MobileScannerErrorCode.permissionDenied;
  69 + }
  70 +
63 /// Create a copy of this state with the given parameters. 71 /// Create a copy of this state with the given parameters.
64 MobileScannerState copyWith({ 72 MobileScannerState copyWith({
65 int? availableCameras, 73 int? availableCameras,