Navaron Bracke

handle camera permission error in the controller

@@ -159,14 +159,23 @@ class MobileScannerController { @@ -159,14 +159,23 @@ class MobileScannerController {
159 .values[await _methodChannel.invokeMethod('state') as int? ?? 0]; 159 .values[await _methodChannel.invokeMethod('state') as int? ?? 0];
160 switch (state) { 160 switch (state) {
161 case MobileScannerState.undetermined: 161 case MobileScannerState.undetermined:
  162 + try {
162 final bool result = 163 final bool result =
163 await _methodChannel.invokeMethod('request') as bool? ?? false; 164 await _methodChannel.invokeMethod('request') as bool? ?? false;
  165 +
164 if (!result) { 166 if (!result) {
165 - isStarting = false;  
166 throw const MobileScannerException( 167 throw const MobileScannerException(
167 errorCode: MobileScannerErrorCode.permissionDenied, 168 errorCode: MobileScannerErrorCode.permissionDenied,
168 ); 169 );
169 } 170 }
  171 + } catch (error) {
  172 + throw const MobileScannerException(
  173 + errorCode: MobileScannerErrorCode.genericError,
  174 + );
  175 + } finally {
  176 + isStarting = false;
  177 + }
  178 +
170 break; 179 break;
171 case MobileScannerState.denied: 180 case MobileScannerState.denied:
172 isStarting = false; 181 isStarting = false;