From 161e22266f636cbc4d34ab4cee6888f8ed6cd3c1 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 11 May 2024 07:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Allows=20`wrapControllerMethod`?= =?UTF-8?q?=20to=20return=20nullable=20result=20(#241)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #240 --- CHANGELOG.md | 10 ++++++++++ example/pubspec.yaml | 2 +- lib/src/states/camera_picker_state.dart | 24 +++++++++++++++--------- pubspec.yaml | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69ab610..46e456e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ that can be found in the LICENSE file. --> See the [Migration Guide](guides/migration_guide.md) for breaking changes between versions. +## 4.2.2 + +### Fixes + +- Allows `wrapControllerMethod` to return nullable result + +### Improvements + +- Provide the back button when no controller has been initialized. + ## 4.2.1 ### Fixes diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b1f9145..126bc6b 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.2.1+33 +version: 4.2.2+34 publish_to: none environment: diff --git a/lib/src/states/camera_picker_state.dart b/lib/src/states/camera_picker_state.dart index 906d683..8243325 100644 --- a/lib/src/states/camera_picker_state.dart +++ b/lib/src/states/camera_picker_state.dart @@ -304,7 +304,7 @@ class CameraPickerState extends State /// /// 对于 [CameraController] 的方法增加是否无效的控制。 /// 如果 [T] 是非 void 且方法无效,返回 [fallback]。 - Future wrapControllerMethod( + Future wrapControllerMethod( String key, Future Function() method, { CameraDescription? description, @@ -313,7 +313,7 @@ class CameraPickerState extends State }) async { description ??= currentCamera; if (invalidControllerMethods[description]!.contains(key)) { - return fallback!; + return fallback; } try { return await method(); @@ -431,37 +431,37 @@ class CameraPickerState extends State () => newController.getExposureOffsetStepSize(), description: description, fallback: exposureStep, - ).then((value) => exposureStep = value), + ).then((value) => exposureStep = value!), wrapControllerMethod( 'getMaxExposureOffset', () => newController.getMaxExposureOffset(), description: description, fallback: maxAvailableExposureOffset, - ).then((value) => maxAvailableExposureOffset = value), + ).then((value) => maxAvailableExposureOffset = value!), wrapControllerMethod( 'getMinExposureOffset', () => newController.getMinExposureOffset(), description: description, fallback: minAvailableExposureOffset, - ).then((value) => minAvailableExposureOffset = value), + ).then((value) => minAvailableExposureOffset = value!), wrapControllerMethod( 'getMaxZoomLevel', () => newController.getMaxZoomLevel(), description: description, fallback: maxAvailableZoom, - ).then((value) => maxAvailableZoom = value), + ).then((value) => maxAvailableZoom = value!), wrapControllerMethod( 'getMinZoomLevel', () => newController.getMinZoomLevel(), description: description, fallback: minAvailableZoom, - ).then((value) => minAvailableZoom = value), + ).then((value) => minAvailableZoom = value!), wrapControllerMethod( 'getMinZoomLevel', () => newController.getMinZoomLevel(), description: description, fallback: minAvailableZoom, - ).then((value) => minAvailableZoom = value), + ).then((value) => minAvailableZoom = value!), if (pickerConfig.lockCaptureOrientation != null) wrapControllerMethod( 'lockCaptureOrientation', @@ -1172,6 +1172,13 @@ class CameraPickerState extends State /// This displayed at the top of the screen. /// 该区域显示在屏幕上方。 Widget buildSettingActions(BuildContext context) { + if (innerController == null) { + return Container( + alignment: AlignmentDirectional.topStart, + padding: const EdgeInsets.symmetric(horizontal: 12), + child: buildBackButton(context), + ); + } return buildInitializeWrapper( builder: (CameraValue v, __) { if (v.isRecordingVideo) { @@ -1787,7 +1794,6 @@ class CameraPickerState extends State children: [ Semantics( sortKey: const OrdinalSortKey(0), - hidden: innerController == null, child: buildSettingActions(context), ), const Spacer(), diff --git a/pubspec.yaml b/pubspec.yaml index 8ad66d4..9200049 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_camera_picker -version: 4.2.1 +version: 4.2.2 description: | A camera picker for Flutter projects based on WeChat's UI, which is also a separate runnable extension to the