Skip to content

Conversation

navaronbracke
Copy link
Collaborator

Part of #1086 but split off to make the other diff smaller

- require_trailing_commas
- unnecessary_library_directive
- unnecessary_library_directive
- prefer_single_quotes
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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']
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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.',
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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),
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

@navaronbracke navaronbracke Sep 18, 2024

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 {
Copy link
Collaborator Author

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].
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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

@navaronbracke navaronbracke merged commit c3271f0 into juliansteenbakker:master Sep 18, 2024
5 checks passed
@navaronbracke navaronbracke deleted the error_codes_cleanup branch September 18, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant