Skip to content

Commit

Permalink
parse code from platform exception; use shorter message; use if-case …
Browse files Browse the repository at this point in the history
…to extract size
  • Loading branch information
navaronbracke committed Sep 18, 2024
1 parent 1ab7f5a commit 41382ee
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/src/method_channel/mobile_scanner_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
throw const MobileScannerException(
errorCode: MobileScannerErrorCode.controllerAlreadyInitialized,
errorDetails: MobileScannerErrorDetails(
message:
'The scanner was already started. Call stop() before calling start() again.',
message: 'The scanner was already started.',
),
);
}
Expand All @@ -204,7 +203,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
);
} on PlatformException catch (error) {
throw MobileScannerException(
errorCode: MobileScannerErrorCode.genericError,
errorCode: MobileScannerErrorCode.fromPlatformException(error),
errorDetails: MobileScannerErrorDetails(
code: error.code,
details: error.details as Object?,
Expand Down Expand Up @@ -240,17 +239,13 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
startResult['currentTorchState'] as int? ?? -1,
);

final Map<Object?, Object?>? sizeInfo =
startResult['size'] as Map<Object?, Object?>?;
final double? width = sizeInfo?['width'] as double?;
final double? height = sizeInfo?['height'] as double?;

final Size size;

if (width == null || height == null) {
size = Size.zero;
} else {
if (startResult['size']
case {'width': final double width, 'height': final double height}) {
size = Size(width, height);
} else {
size = Size.zero;
}

return MobileScannerViewAttributes(
Expand Down

0 comments on commit 41382ee

Please sign in to comment.