Navaron Bracke

parse code from platform exception; use shorter message; use if-case to extract size

@@ -187,8 +187,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -187,8 +187,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
187 throw const MobileScannerException( 187 throw const MobileScannerException(
188 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized, 188 errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
189 errorDetails: MobileScannerErrorDetails( 189 errorDetails: MobileScannerErrorDetails(
190 - message:  
191 - 'The scanner was already started. Call stop() before calling start() again.', 190 + message: 'The scanner was already started.',
192 ), 191 ),
193 ); 192 );
194 } 193 }
@@ -204,7 +203,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -204,7 +203,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
204 ); 203 );
205 } on PlatformException catch (error) { 204 } on PlatformException catch (error) {
206 throw MobileScannerException( 205 throw MobileScannerException(
207 - errorCode: MobileScannerErrorCode.genericError, 206 + errorCode: MobileScannerErrorCode.fromPlatformException(error),
208 errorDetails: MobileScannerErrorDetails( 207 errorDetails: MobileScannerErrorDetails(
209 code: error.code, 208 code: error.code,
210 details: error.details as Object?, 209 details: error.details as Object?,
@@ -240,17 +239,13 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -240,17 +239,13 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
240 startResult['currentTorchState'] as int? ?? -1, 239 startResult['currentTorchState'] as int? ?? -1,
241 ); 240 );
242 241
243 - final Map<Object?, Object?>? sizeInfo =  
244 - startResult['size'] as Map<Object?, Object?>?;  
245 - final double? width = sizeInfo?['width'] as double?;  
246 - final double? height = sizeInfo?['height'] as double?;  
247 -  
248 final Size size; 242 final Size size;
249 243
250 - if (width == null || height == null) {  
251 - size = Size.zero;  
252 - } else { 244 + if (startResult['size']
  245 + case {'width': final double width, 'height': final double height}) {
253 size = Size(width, height); 246 size = Size(width, height);
  247 + } else {
  248 + size = Size.zero;
254 } 249 }
255 250
256 return MobileScannerViewAttributes( 251 return MobileScannerViewAttributes(