Skip to content

Commit 6f97f50

Browse files
authored
🥅 Catch exceptions for controller methods (#191)
Fixes #190, fixes fluttercandies/flutter_wechat_assets_picker#480
1 parent b04afc3 commit 6f97f50

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-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.1
10+
11+
### Fixes
12+
13+
- Fix uncaught exceptions for controller methods.
14+
915
## 4.0.0
1016

1117
To know more about breaking changes, see [Migration Guide][].

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.0+25
3+
version: 4.0.1+26
44
publish_to: none
55

66
environment:

lib/src/states/camera_picker_state.dart

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,28 +352,38 @@ class CameraPickerState extends State<CameraPicker>
352352
..start();
353353
await Future.wait(
354354
<Future<void>>[
355-
if (pickerConfig.lockCaptureOrientation != null)
356-
newController
357-
.lockCaptureOrientation(pickerConfig.lockCaptureOrientation),
358355
newController
359356
.getExposureOffsetStepSize()
360-
.then((double value) => exposureStep = value),
357+
.then((double value) => exposureStep = value)
358+
.catchError((_) => exposureStep),
361359
newController
362360
.getMaxExposureOffset()
363-
.then((double value) => maxAvailableExposureOffset = value),
361+
.then((double value) => maxAvailableExposureOffset = value)
362+
.catchError((_) => maxAvailableExposureOffset),
364363
newController
365364
.getMinExposureOffset()
366-
.then((double value) => minAvailableExposureOffset = value),
365+
.then((double value) => minAvailableExposureOffset = value)
366+
.catchError((_) => minAvailableExposureOffset),
367367
newController
368368
.getMaxZoomLevel()
369-
.then((double value) => maxAvailableZoom = value),
369+
.then((double value) => maxAvailableZoom = value)
370+
.catchError((_) => maxAvailableZoom),
370371
newController
371372
.getMinZoomLevel()
372-
.then((double value) => minAvailableZoom = value),
373+
.then((double value) => minAvailableZoom = value)
374+
.catchError((_) => minAvailableZoom),
375+
if (pickerConfig.lockCaptureOrientation != null)
376+
newController
377+
.lockCaptureOrientation(pickerConfig.lockCaptureOrientation)
378+
.catchError((_) {}),
373379
if (pickerConfig.preferredFlashMode != FlashMode.auto)
374-
newController.setFlashMode(pickerConfig.preferredFlashMode),
380+
newController
381+
.setFlashMode(pickerConfig.preferredFlashMode)
382+
.catchError((_) {
383+
validFlashModes[currentCamera]
384+
?.remove(pickerConfig.preferredFlashMode);
385+
}),
375386
],
376-
eagerError: true,
377387
);
378388
stopwatch.stop();
379389
realDebugPrint("${stopwatch.elapsed} for config's update.");
@@ -747,7 +757,7 @@ class CameraPickerState extends State<CameraPicker>
747757
isShootingButtonAnimate = false;
748758
});
749759
}
750-
if (controller.value.isRecordingVideo) {
760+
if (innerController?.value.isRecordingVideo == true) {
751761
lastShootingButtonPressedPosition = null;
752762
safeSetState(() {});
753763
stopRecordingVideo();
@@ -869,20 +879,23 @@ class CameraPickerState extends State<CameraPicker>
869879
////////////////////////////////////////////////////////////////////////////
870880
871881
PointerUpEventListener? get onPointerUp {
872-
if (enableRecording && !enableTapRecording) {
882+
if (innerController != null && enableRecording && !enableTapRecording) {
873883
return recordDetectionCancel;
874884
}
875885
return null;
876886
}
877887

878888
PointerMoveEventListener? onPointerMove(BoxConstraints c) {
879-
if (enablePullToZoomInRecord) {
889+
if (innerController != null && enablePullToZoomInRecord) {
880890
return (PointerMoveEvent e) => onShootingButtonMove(e, c);
881891
}
882892
return null;
883893
}
884894

885895
GestureTapCallback? get onTap {
896+
if (innerController == null) {
897+
return null;
898+
}
886899
if (enableTapRecording) {
887900
if (innerController?.value.isRecordingVideo ?? false) {
888901
return stopRecordingVideo;
@@ -901,6 +914,9 @@ class CameraPickerState extends State<CameraPicker>
901914
}
902915

903916
String? get onTapHint {
917+
if (innerController == null) {
918+
return null;
919+
}
904920
if (enableTapRecording) {
905921
if (innerController?.value.isRecordingVideo ?? false) {
906922
return textDelegate.sActionStopRecordingHint;
@@ -914,13 +930,19 @@ class CameraPickerState extends State<CameraPicker>
914930
}
915931

916932
GestureLongPressCallback? get onLongPress {
933+
if (innerController == null) {
934+
return null;
935+
}
917936
if (enableRecording && !enableTapRecording) {
918937
return recordDetection;
919938
}
920939
return null;
921940
}
922941

923942
String? get onLongPressHint {
943+
if (innerController == null) {
944+
return null;
945+
}
924946
if (enableRecording && !enableTapRecording) {
925947
return textDelegate.sActionRecordHint;
926948
}

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.0
4+
version: 4.0.1
55

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

0 commit comments

Comments
 (0)