From 3301d20eb82e60cf1d37c2fb9a0b3ce590354a37 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 26 Oct 2023 10:29:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Handle=20exceptions=20after?= =?UTF-8?q?=20all=20flows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/states/camera_picker_state.dart | 26 +++++++++++-------- .../states/camera_picker_viewer_state.dart | 18 ++++++------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index e65cc9f..aacc51e 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -343,6 +343,7 @@ class CameraPickerState extends State StackTrace.current, pickerConfig.onError, ); + return; } initFlashModesForCameras(); @@ -622,9 +623,10 @@ class CameraPickerState extends State await controller.setExposureMode(newMode); } catch (e, s) { handleErrorWithHandler(e, s, pickerConfig.onError); + } finally { + restartExposureModeDisplayTimer(); + restartExposureFadeOutTimer(); } - restartExposureModeDisplayTimer(); - restartExposureFadeOutTimer(); } /// Use the [position] to set exposure and focus. @@ -714,17 +716,18 @@ class CameraPickerState extends State ), ); } catch (e, s) { - handleErrorWithHandler(e, s, pickerConfig.onError); hasError = true; currentExposureSliderOffset.value = previousSliderOffsetValue; currentExposureOffset.value = previousOffsetValue; + handleErrorWithHandler(e, s, pickerConfig.onError); + } finally { + if (!hasError && !isFocusPointDisplays.value) { + isFocusPointDisplays.value = true; + } + restartExposurePointDisplayTimer(); + restartExposureModeDisplayTimer(); + restartExposureFadeOutTimer(); } - if (!hasError && !isFocusPointDisplays.value) { - isFocusPointDisplays.value = true; - } - restartExposurePointDisplayTimer(); - restartExposureModeDisplayTimer(); - restartExposureFadeOutTimer(); } /// Request to set the focus and the exposure point on the [localPosition], @@ -897,8 +900,9 @@ class CameraPickerState extends State recordCountdownTimer?.cancel(); isShootingButtonAnimate = false; handleErrorWithHandler(e, s, pickerConfig.onError); + } finally { + recordStopwatch.stop(); } - recordStopwatch.stop(); } finally { safeSetState(() {}); } @@ -945,9 +949,9 @@ class CameraPickerState extends State await controller.resumePreview(); } } catch (e, s) { - handleErrorWithHandler(e, s, pickerConfig.onError); handleError(); initCameras(); + handleErrorWithHandler(e, s, pickerConfig.onError); } finally { isControllerBusy = false; safeSetState(() {}); diff --git a/lib/src/states/camera_picker_viewer_state.dart b/lib/src/states/camera_picker_viewer_state.dart index ac9f1ed..05479ee 100644 --- a/lib/src/states/camera_picker_viewer_state.dart +++ b/lib/src/states/camera_picker_viewer_state.dart @@ -15,6 +15,7 @@ import '../constants/constants.dart'; import '../constants/enums.dart'; import '../constants/styles.dart'; import '../constants/type_defs.dart'; +import '../internals/extensions.dart'; import '../internals/methods.dart'; import '../widgets/camera_picker.dart'; import '../widgets/camera_picker_viewer.dart'; @@ -83,9 +84,7 @@ class CameraPickerViewerState extends State { realDebugPrint('Error when initializing video controller: $e'); handleErrorWithHandler(e, s, onError); } finally { - if (mounted) { - setState(() {}); - } + safeSetState(() {}); } } @@ -141,12 +140,11 @@ class CameraPickerViewerState extends State { ); } catch (e, s) { handleErrorWithHandler(e, s, onError); + } finally { + safeSetState(() { + isSavingEntity = false; + }); } - isSavingEntity = false; - if (mounted) { - setState(() {}); - } - return; } AssetEntity? entity; try { @@ -184,7 +182,9 @@ class CameraPickerViewerState extends State { realDebugPrint('Saving entity failed: $e'); handleErrorWithHandler(e, s, onError); } finally { - isSavingEntity = false; + safeSetState(() { + isSavingEntity = false; + }); if (mounted) { Navigator.of(context).pop(entity); } From 7f30934cb314c3aea9652016388855a741665350 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 26 Oct 2023 10:39:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=204.0.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ example/pubspec.yaml | 2 +- pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d49d6d..2176ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.4 + +### Fixes + +- Handle exceptions after all flows. + ## 4.0.3 ### Fixes diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 72c0893..3d11d82 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: wechat_camera_picker_demo description: A new Flutter project. -version: 4.0.3+28 +version: 4.0.4+29 publish_to: none environment: diff --git a/pubspec.yaml b/pubspec.yaml index b22b82d..4f2e15d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_camera_picker -version: 4.0.3 +version: 4.0.4 description: | A camera picker for Flutter projects based on WeChat's UI, which is also a separate runnable extension to the