Skip to content
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: start should reset error code #1249

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bugs fixed:
* [Apple] Fixed an issue which caused the scanWindow to always be present, even when reset to no value.
* [Apple] Fixed an issue that caused the barcode size to report the wrong height.
* [Apple] Fixed a bug that caused the corner points to not be returned in clockwise orientation.
* Fixed a bug where the permission error code is not reset when the scanner is started correctly.

Improvements:
* Added a basic barcode overlay widget, for use with the camera preview.
Expand Down
22 changes: 21 additions & 1 deletion lib/src/mobile_scanner_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
// Provide the current torch state.
// Updates are provided by the `torchStateStream`.
torchState: viewAttributes.currentTorchMode,
// At this point the scanner started correctly, so reset any previous error.
resetError: true,
);
}
} on MobileScannerException catch (error) {
Expand Down Expand Up @@ -348,9 +350,27 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
torchState: oldTorchState == TorchState.unavailable
? TorchState.unavailable
: TorchState.off,
resetError: true,
);

await MobileScannerPlatform.instance.stop();
try {
await MobileScannerPlatform.instance.stop();
} catch (error, stackTrace) {
if (_isDisposed) {
return;
}

// If the camera failed to stop, report the error.
value = value.copyWith(
error: MobileScannerException(
errorCode: MobileScannerErrorCode.genericError,
errorDetails: MobileScannerErrorDetails(
details: stackTrace.toString(),
message: error.toString(),
),
),
);
}
}

/// Switch between the front and back camera.
Expand Down
5 changes: 4 additions & 1 deletion lib/src/objects/mobile_scanner_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class MobileScannerState {
}

/// Create a copy of this state with the given parameters.
///
/// If [resetError] is `true`, the error will be reset to null.
MobileScannerState copyWith({
int? availableCameras,
CameraFacing? cameraDirection,
Expand All @@ -81,11 +83,12 @@ class MobileScannerState {
Size? size,
TorchState? torchState,
double? zoomScale,
bool resetError = false,
}) {
return MobileScannerState(
availableCameras: availableCameras ?? this.availableCameras,
cameraDirection: cameraDirection ?? this.cameraDirection,
error: error,
error: resetError ? null : error ?? this.error,
isInitialized: isInitialized ?? this.isInitialized,
isRunning: isRunning ?? this.isRunning,
size: size ?? this.size,
Expand Down