Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Allows wrapControllerMethod to return nullable result #241

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.2.1+33
version: 4.2.2+34
publish_to: none

environment:
Expand Down
24 changes: 15 additions & 9 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class CameraPickerState extends State<CameraPicker>
///
/// 对于 [CameraController] 的方法增加是否无效的控制。
/// 如果 [T] 是非 void 且方法无效,返回 [fallback]。
Future<T> wrapControllerMethod<T>(
Future<T?> wrapControllerMethod<T>(
String key,
Future<T> Function() method, {
CameraDescription? description,
Expand All @@ -313,7 +313,7 @@ class CameraPickerState extends State<CameraPicker>
}) async {
description ??= currentCamera;
if (invalidControllerMethods[description]!.contains(key)) {
return fallback!;
return fallback;
}
try {
return await method();
Expand Down Expand Up @@ -431,37 +431,37 @@ class CameraPickerState extends State<CameraPicker>
() => 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<void>(
'lockCaptureOrientation',
Expand Down Expand Up @@ -1172,6 +1172,13 @@ class CameraPickerState extends State<CameraPicker>
/// 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) {
Expand Down Expand Up @@ -1787,7 +1794,6 @@ class CameraPickerState extends State<CameraPicker>
children: <Widget>[
Semantics(
sortKey: const OrdinalSortKey(0),
hidden: innerController == null,
child: buildSettingActions(context),
),
const Spacer(),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading