Skip to content

Commit

Permalink
Handles exceptions if locking methods are failed (#196)
Browse files Browse the repository at this point in the history
Probably fixes #194
  • Loading branch information
AlexV525 authored Sep 10, 2023
1 parent 6f97f50 commit be5c1de
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->

See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.

## 4.0.2

### Fixes

- Handles exceptions if locking methods are failed.

## 4.0.1

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: wechat_camera_picker_demo
description: A new Flutter project.
version: 4.0.1+26
version: 4.0.2+27
publish_to: none

environment:
Expand Down
23 changes: 10 additions & 13 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,13 @@ class CameraPickerState extends State<CameraPicker>
final ExposureMode previousExposureMode = controller.value.exposureMode;
try {
await Future.wait(<Future<void>>[
controller.setFocusMode(FocusMode.locked),
controller.setFocusMode(FocusMode.locked).catchError((e, s) {
handleErrorWithHandler(e, pickerConfig.onError, s: s);
}),
if (previousExposureMode != ExposureMode.locked)
controller.setExposureMode(ExposureMode.locked),
controller.setExposureMode(ExposureMode.locked).catchError((e, s) {
handleErrorWithHandler(e, pickerConfig.onError, s: s);
}),
]);
final XFile file = await controller.takePicture();
await controller.pausePreview();
Expand All @@ -720,9 +724,8 @@ class CameraPickerState extends State<CameraPicker>
controller.setExposureMode(previousExposureMode),
]);
await controller.resumePreview();
} catch (e) {
realDebugPrint('Error when preview the captured file: $e');
handleErrorWithHandler(e, pickerConfig.onError);
} catch (e, s) {
handleErrorWithHandler(e, pickerConfig.onError, s: s);
} finally {
isControllerBusy = false;
safeSetState(() {});
Expand Down Expand Up @@ -784,17 +787,13 @@ class CameraPickerState extends State<CameraPicker>
..start();
} catch (e, s) {
isControllerBusy = false;
realDebugPrint('Error when start recording video: $e');
if (!controller.value.isRecordingVideo) {
handleErrorWithHandler(e, pickerConfig.onError, s: s);
return;
}
try {
await controller.stopVideoRecording();
} catch (e, s) {
realDebugPrint(
'Error when stop recording video after an error start: $e',
);
recordCountdownTimer?.cancel();
isShootingButtonAnimate = false;
handleErrorWithHandler(e, pickerConfig.onError, s: s);
Expand Down Expand Up @@ -846,11 +845,9 @@ class CameraPickerState extends State<CameraPicker>
await controller.resumePreview();
}
} catch (e, s) {
realDebugPrint('Error when stop recording video: $e');
realDebugPrint('Try to initialize a new CameraController...');
initCameras();
handleError();
handleErrorWithHandler(e, pickerConfig.onError, s: s);
handleError();
initCameras();
} finally {
isControllerBusy = false;
safeSetState(() {});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: wechat_camera_picker
description: A camera picker based on WeChat's UI which is a separate runnable extension to wechat_assets_picker.
repository: https://github.com/fluttercandies/flutter_wechat_camera_picker
version: 4.0.1
version: 4.0.2

environment:
sdk: ">=2.18.0 <3.0.0"
Expand Down

0 comments on commit be5c1de

Please sign in to comment.