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 - final bool result =  
163 - await _methodChannel.invokeMethod('request') as bool? ?? false;  
164 - if (!result) {  
165 - isStarting = false; 162 + try {
  163 + final bool result =
  164 + await _methodChannel.invokeMethod('request') as bool? ?? false;
  165 +
  166 + if (!result) {
  167 + throw const MobileScannerException(
  168 + errorCode: MobileScannerErrorCode.permissionDenied,
  169 + );
  170 + }
  171 + } catch (error) {
166 throw const MobileScannerException( 172 throw const MobileScannerException(
167 - errorCode: MobileScannerErrorCode.permissionDenied, 173 + errorCode: MobileScannerErrorCode.genericError,
168 ); 174 );
  175 + } finally {
  176 + isStarting = false;
169 } 177 }
  178 +
170 break; 179 break;
171 case MobileScannerState.denied: 180 case MobileScannerState.denied:
172 isStarting = false; 181 isStarting = false;