Skip to content

Commit 161e222

Browse files
authored
🐛 Allows wrapControllerMethod to return nullable result (#241)
Fixes #240
1 parent 8a5ff85 commit 161e222

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ that can be found in the LICENSE file. -->
66

77
See the [Migration Guide](guides/migration_guide.md) for breaking changes between versions.
88

9+
## 4.2.2
10+
11+
### Fixes
12+
13+
- Allows `wrapControllerMethod` to return nullable result
14+
15+
### Improvements
16+
17+
- Provide the back button when no controller has been initialized.
18+
919
## 4.2.1
1020

1121
### Fixes

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.2.1+33
3+
version: 4.2.2+34
44
publish_to: none
55

66
environment:

lib/src/states/camera_picker_state.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class CameraPickerState extends State<CameraPicker>
304304
///
305305
/// 对于 [CameraController] 的方法增加是否无效的控制。
306306
/// 如果 [T] 是非 void 且方法无效,返回 [fallback]
307-
Future<T> wrapControllerMethod<T>(
307+
Future<T?> wrapControllerMethod<T>(
308308
String key,
309309
Future<T> Function() method, {
310310
CameraDescription? description,
@@ -313,7 +313,7 @@ class CameraPickerState extends State<CameraPicker>
313313
}) async {
314314
description ??= currentCamera;
315315
if (invalidControllerMethods[description]!.contains(key)) {
316-
return fallback!;
316+
return fallback;
317317
}
318318
try {
319319
return await method();
@@ -431,37 +431,37 @@ class CameraPickerState extends State<CameraPicker>
431431
() => newController.getExposureOffsetStepSize(),
432432
description: description,
433433
fallback: exposureStep,
434-
).then((value) => exposureStep = value),
434+
).then((value) => exposureStep = value!),
435435
wrapControllerMethod(
436436
'getMaxExposureOffset',
437437
() => newController.getMaxExposureOffset(),
438438
description: description,
439439
fallback: maxAvailableExposureOffset,
440-
).then((value) => maxAvailableExposureOffset = value),
440+
).then((value) => maxAvailableExposureOffset = value!),
441441
wrapControllerMethod(
442442
'getMinExposureOffset',
443443
() => newController.getMinExposureOffset(),
444444
description: description,
445445
fallback: minAvailableExposureOffset,
446-
).then((value) => minAvailableExposureOffset = value),
446+
).then((value) => minAvailableExposureOffset = value!),
447447
wrapControllerMethod(
448448
'getMaxZoomLevel',
449449
() => newController.getMaxZoomLevel(),
450450
description: description,
451451
fallback: maxAvailableZoom,
452-
).then((value) => maxAvailableZoom = value),
452+
).then((value) => maxAvailableZoom = value!),
453453
wrapControllerMethod(
454454
'getMinZoomLevel',
455455
() => newController.getMinZoomLevel(),
456456
description: description,
457457
fallback: minAvailableZoom,
458-
).then((value) => minAvailableZoom = value),
458+
).then((value) => minAvailableZoom = value!),
459459
wrapControllerMethod(
460460
'getMinZoomLevel',
461461
() => newController.getMinZoomLevel(),
462462
description: description,
463463
fallback: minAvailableZoom,
464-
).then((value) => minAvailableZoom = value),
464+
).then((value) => minAvailableZoom = value!),
465465
if (pickerConfig.lockCaptureOrientation != null)
466466
wrapControllerMethod<void>(
467467
'lockCaptureOrientation',
@@ -1172,6 +1172,13 @@ class CameraPickerState extends State<CameraPicker>
11721172
/// This displayed at the top of the screen.
11731173
/// 该区域显示在屏幕上方。
11741174
Widget buildSettingActions(BuildContext context) {
1175+
if (innerController == null) {
1176+
return Container(
1177+
alignment: AlignmentDirectional.topStart,
1178+
padding: const EdgeInsets.symmetric(horizontal: 12),
1179+
child: buildBackButton(context),
1180+
);
1181+
}
11751182
return buildInitializeWrapper(
11761183
builder: (CameraValue v, __) {
11771184
if (v.isRecordingVideo) {
@@ -1787,7 +1794,6 @@ class CameraPickerState extends State<CameraPicker>
17871794
children: <Widget>[
17881795
Semantics(
17891796
sortKey: const OrdinalSortKey(0),
1790-
hidden: innerController == null,
17911797
child: buildSettingActions(context),
17921798
),
17931799
const Spacer(),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: wechat_camera_picker
2-
version: 4.2.1
2+
version: 4.2.2
33
description: |
44
A camera picker for Flutter projects based on WeChat's UI,
55
which is also a separate runnable extension to the

0 commit comments

Comments
 (0)