Showing
1 changed file
with
18 additions
and
17 deletions
| @@ -206,32 +206,33 @@ class MobileScannerController { | @@ -206,32 +206,33 @@ class MobileScannerController { | ||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | switch (state) { | 208 | switch (state) { |
| 209 | + // Android does not have an undetermined permission state. | ||
| 210 | + // So if the permission state is denied, just request it now. | ||
| 209 | case MobileScannerState.undetermined: | 211 | case MobileScannerState.undetermined: |
| 210 | - bool result = false; | ||
| 211 | - | 212 | + case MobileScannerState.denied: |
| 212 | try { | 213 | try { |
| 213 | - result = | 214 | + final bool granted = |
| 214 | await _methodChannel.invokeMethod('request') as bool? ?? false; | 215 | await _methodChannel.invokeMethod('request') as bool? ?? false; |
| 215 | - } catch (error) { | ||
| 216 | - isStarting = false; | ||
| 217 | - throw const MobileScannerException( | ||
| 218 | - errorCode: MobileScannerErrorCode.genericError, | ||
| 219 | - ); | ||
| 220 | - } | ||
| 221 | 216 | ||
| 222 | - if (!result) { | 217 | + if (!granted) { |
| 218 | + isStarting = false; | ||
| 219 | + throw const MobileScannerException( | ||
| 220 | + errorCode: MobileScannerErrorCode.permissionDenied, | ||
| 221 | + ); | ||
| 222 | + } | ||
| 223 | + } on PlatformException catch (error) { | ||
| 223 | isStarting = false; | 224 | isStarting = false; |
| 224 | - throw const MobileScannerException( | ||
| 225 | - errorCode: MobileScannerErrorCode.permissionDenied, | 225 | + throw MobileScannerException( |
| 226 | + errorCode: MobileScannerErrorCode.genericError, | ||
| 227 | + errorDetails: MobileScannerErrorDetails( | ||
| 228 | + code: error.code, | ||
| 229 | + details: error.details as Object?, | ||
| 230 | + message: error.message, | ||
| 231 | + ), | ||
| 226 | ); | 232 | ); |
| 227 | } | 233 | } |
| 228 | 234 | ||
| 229 | break; | 235 | break; |
| 230 | - case MobileScannerState.denied: | ||
| 231 | - isStarting = false; | ||
| 232 | - throw const MobileScannerException( | ||
| 233 | - errorCode: MobileScannerErrorCode.permissionDenied, | ||
| 234 | - ); | ||
| 235 | case MobileScannerState.authorized: | 236 | case MobileScannerState.authorized: |
| 236 | break; | 237 | break; |
| 237 | } | 238 | } |
-
Please register or login to post a comment