Skip to content

Commit

Permalink
🥅 Catch exceptions for controller methods (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Aug 29, 2023
1 parent b04afc3 commit 6f97f50
Show file tree
Hide file tree
Showing 4 changed files with 43 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.1

### Fixes

- Fix uncaught exceptions for controller methods.

## 4.0.0

To know more about breaking changes, see [Migration Guide][].
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.0+25
version: 4.0.1+26
publish_to: none

environment:
Expand Down
48 changes: 35 additions & 13 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,28 +352,38 @@ class CameraPickerState extends State<CameraPicker>
..start();
await Future.wait(
<Future<void>>[
if (pickerConfig.lockCaptureOrientation != null)
newController
.lockCaptureOrientation(pickerConfig.lockCaptureOrientation),
newController
.getExposureOffsetStepSize()
.then((double value) => exposureStep = value),
.then((double value) => exposureStep = value)
.catchError((_) => exposureStep),
newController
.getMaxExposureOffset()
.then((double value) => maxAvailableExposureOffset = value),
.then((double value) => maxAvailableExposureOffset = value)
.catchError((_) => maxAvailableExposureOffset),
newController
.getMinExposureOffset()
.then((double value) => minAvailableExposureOffset = value),
.then((double value) => minAvailableExposureOffset = value)
.catchError((_) => minAvailableExposureOffset),
newController
.getMaxZoomLevel()
.then((double value) => maxAvailableZoom = value),
.then((double value) => maxAvailableZoom = value)
.catchError((_) => maxAvailableZoom),
newController
.getMinZoomLevel()
.then((double value) => minAvailableZoom = value),
.then((double value) => minAvailableZoom = value)
.catchError((_) => minAvailableZoom),
if (pickerConfig.lockCaptureOrientation != null)
newController
.lockCaptureOrientation(pickerConfig.lockCaptureOrientation)
.catchError((_) {}),
if (pickerConfig.preferredFlashMode != FlashMode.auto)
newController.setFlashMode(pickerConfig.preferredFlashMode),
newController
.setFlashMode(pickerConfig.preferredFlashMode)
.catchError((_) {
validFlashModes[currentCamera]
?.remove(pickerConfig.preferredFlashMode);
}),
],
eagerError: true,
);
stopwatch.stop();
realDebugPrint("${stopwatch.elapsed} for config's update.");
Expand Down Expand Up @@ -747,7 +757,7 @@ class CameraPickerState extends State<CameraPicker>
isShootingButtonAnimate = false;
});
}
if (controller.value.isRecordingVideo) {
if (innerController?.value.isRecordingVideo == true) {
lastShootingButtonPressedPosition = null;
safeSetState(() {});
stopRecordingVideo();
Expand Down Expand Up @@ -869,20 +879,23 @@ class CameraPickerState extends State<CameraPicker>
////////////////////////////////////////////////////////////////////////////
PointerUpEventListener? get onPointerUp {
if (enableRecording && !enableTapRecording) {
if (innerController != null && enableRecording && !enableTapRecording) {
return recordDetectionCancel;
}
return null;
}

PointerMoveEventListener? onPointerMove(BoxConstraints c) {
if (enablePullToZoomInRecord) {
if (innerController != null && enablePullToZoomInRecord) {
return (PointerMoveEvent e) => onShootingButtonMove(e, c);
}
return null;
}

GestureTapCallback? get onTap {
if (innerController == null) {
return null;
}
if (enableTapRecording) {
if (innerController?.value.isRecordingVideo ?? false) {
return stopRecordingVideo;
Expand All @@ -901,6 +914,9 @@ class CameraPickerState extends State<CameraPicker>
}

String? get onTapHint {
if (innerController == null) {
return null;
}
if (enableTapRecording) {
if (innerController?.value.isRecordingVideo ?? false) {
return textDelegate.sActionStopRecordingHint;
Expand All @@ -914,13 +930,19 @@ class CameraPickerState extends State<CameraPicker>
}

GestureLongPressCallback? get onLongPress {
if (innerController == null) {
return null;
}
if (enableRecording && !enableTapRecording) {
return recordDetection;
}
return null;
}

String? get onLongPressHint {
if (innerController == null) {
return null;
}
if (enableRecording && !enableTapRecording) {
return textDelegate.sActionRecordHint;
}
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.0
version: 4.0.1

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

0 comments on commit 6f97f50

Please sign in to comment.