-
-
Notifications
You must be signed in to change notification settings - Fork 605
fix: Clean up error codes #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Clean up error codes #1180
Conversation
- require_trailing_commas | ||
- unnecessary_library_directive | ||
- unnecessary_library_directive | ||
- prefer_single_quotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do prefer single quotes, and we had one violation. So I turned on the lint.
null, | ||
null | ||
) | ||
mobileScannerCallback(barcodeMap, null, null, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
@override | ||
void didChangeAppLifecycleState(AppLifecycleState state) { | ||
if (!controller.value.isInitialized) { | ||
if (!controller.value.hasCameraPermission) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the scanner has no permission, prevent app lifecycle changes from changing the controller state.
result(FlutterError(code: "MobileScanner", | ||
message: "No image found in analyzeImage!", | ||
details: nil)) | ||
result(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning a non-standard error message, just use nil
if (width == null || height == null) { | ||
size = Size.zero; | ||
} else { | ||
if (startResult['size'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If-case to extract the size
void didChangeAppLifecycleState(AppLifecycleState state) { | ||
if (widget.controller != null) return; | ||
if (!controller.value.isInitialized) { | ||
if (widget.controller != null || !controller.value.hasCameraPermission) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the new getter to fix a bug in the sample.
unsupported; | ||
|
||
/// Convert the given [PlatformException.code] to a [MobileScannerErrorCode]. | ||
factory MobileScannerErrorCode.fromPlatformException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid magic strings, I added a factory constructor for this.
errorDetails: MobileScannerErrorDetails( | ||
message: | ||
'The scanner was already started. Call stop() before calling start() again.', | ||
message: 'The scanner was already started.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a shorter message makes the formatting a bit nicer. We're going to swallow this type of error in the upcoming fix anyway.
@@ -0,0 +1,25 @@ | |||
package dev.steenbakker.mobile_scanner.objects | |||
|
|||
class MobileScannerErrorCodes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidating the error codes in one place. MacOS and iOS also have an equivalent. Will be used by the new fix.
} on PlatformException catch (error) { | ||
throw MobileScannerException( | ||
errorCode: MobileScannerErrorCode.genericError, | ||
errorCode: MobileScannerErrorCode.fromPlatformException(error), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert the incoming error into the right code. The Android/iOS/macOS implementations will be reporting different error codes, depending on the situation.
final double zoomScale; | ||
|
||
/// Whether permission to access the camera was granted. | ||
bool get hasCameraPermission { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new getter is used to fix a bug in our lifecycle handling. (in the samples)
|
||
/// This class represents an exception thrown by the [MobileScannerController] | ||
/// when a barcode scanning error occurs when processing an input frame. | ||
class MobileScannerBarcodeException implements Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error will be used by analyzeImage()
& start()
to report barcode scanning errors from image frames.
That will be added in the actual fix pull request.
import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; | ||
|
||
/// This class represents an exception thrown by the mobile scanner. | ||
/// This class represents an exception thrown by the [MobileScannerController]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot yet use @docImport
but hopefully, we'll be able to address that in the future. (maybe with a lint?)
result(FlutterError(code: "MobileScanner", | ||
message: "No image found in analyzeImage!", | ||
details: nil)) | ||
result(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like on iOS, use nil
Part of #1086 but split off to make the other diff smaller