Navaron Bracke

fix bug with try catch

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