Skip to content

Commit be5c1de

Browse files
authored
Handles exceptions if locking methods are failed (#196)
Probably fixes #194
1 parent 6f97f50 commit be5c1de

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ that can be found in the LICENSE file. -->
66

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

9+
## 4.0.2
10+
11+
### Fixes
12+
13+
- Handles exceptions if locking methods are failed.
14+
915
## 4.0.1
1016

1117
### Fixes

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: wechat_camera_picker_demo
22
description: A new Flutter project.
3-
version: 4.0.1+26
3+
version: 4.0.2+27
44
publish_to: none
55

66
environment:

lib/src/states/camera_picker_state.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,13 @@ class CameraPickerState extends State<CameraPicker>
693693
final ExposureMode previousExposureMode = controller.value.exposureMode;
694694
try {
695695
await Future.wait(<Future<void>>[
696-
controller.setFocusMode(FocusMode.locked),
696+
controller.setFocusMode(FocusMode.locked).catchError((e, s) {
697+
handleErrorWithHandler(e, pickerConfig.onError, s: s);
698+
}),
697699
if (previousExposureMode != ExposureMode.locked)
698-
controller.setExposureMode(ExposureMode.locked),
700+
controller.setExposureMode(ExposureMode.locked).catchError((e, s) {
701+
handleErrorWithHandler(e, pickerConfig.onError, s: s);
702+
}),
699703
]);
700704
final XFile file = await controller.takePicture();
701705
await controller.pausePreview();
@@ -720,9 +724,8 @@ class CameraPickerState extends State<CameraPicker>
720724
controller.setExposureMode(previousExposureMode),
721725
]);
722726
await controller.resumePreview();
723-
} catch (e) {
724-
realDebugPrint('Error when preview the captured file: $e');
725-
handleErrorWithHandler(e, pickerConfig.onError);
727+
} catch (e, s) {
728+
handleErrorWithHandler(e, pickerConfig.onError, s: s);
726729
} finally {
727730
isControllerBusy = false;
728731
safeSetState(() {});
@@ -784,17 +787,13 @@ class CameraPickerState extends State<CameraPicker>
784787
..start();
785788
} catch (e, s) {
786789
isControllerBusy = false;
787-
realDebugPrint('Error when start recording video: $e');
788790
if (!controller.value.isRecordingVideo) {
789791
handleErrorWithHandler(e, pickerConfig.onError, s: s);
790792
return;
791793
}
792794
try {
793795
await controller.stopVideoRecording();
794796
} catch (e, s) {
795-
realDebugPrint(
796-
'Error when stop recording video after an error start: $e',
797-
);
798797
recordCountdownTimer?.cancel();
799798
isShootingButtonAnimate = false;
800799
handleErrorWithHandler(e, pickerConfig.onError, s: s);
@@ -846,11 +845,9 @@ class CameraPickerState extends State<CameraPicker>
846845
await controller.resumePreview();
847846
}
848847
} catch (e, s) {
849-
realDebugPrint('Error when stop recording video: $e');
850-
realDebugPrint('Try to initialize a new CameraController...');
851-
initCameras();
852-
handleError();
853848
handleErrorWithHandler(e, pickerConfig.onError, s: s);
849+
handleError();
850+
initCameras();
854851
} finally {
855852
isControllerBusy = false;
856853
safeSetState(() {});

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: wechat_camera_picker
22
description: A camera picker based on WeChat's UI which is a separate runnable extension to wechat_assets_picker.
33
repository: https://github.com/fluttercandies/flutter_wechat_camera_picker
4-
version: 4.0.1
4+
version: 4.0.2
55

66
environment:
77
sdk: ">=2.18.0 <3.0.0"

0 commit comments

Comments
 (0)