Skip to content

Commit f536fee

Browse files
authored
🚀 Allow the foreground builder to be used all the time (#97)
1 parent 2b29dfa commit f536fee

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ that can be found in the LICENSE file. -->
44

55
# Changelog
66

7+
## 3.2.1
8+
9+
### Improvements
10+
11+
- Allow the foreground builder to be used all the time (#97) .
12+
The signature of the `ForegroundBuilder` has changed
13+
but can be easily migrated.
14+
715
## 3.2.0+1
816

917
### New features

lib/src/constants/type_defs.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ typedef CameraErrorHandler = void Function(
4343
/// {@template wechat_camera_picker.ForegroundBuilder}
4444
/// Build the foreground/overlay widget with the given [CameraValue].
4545
/// 根据给定的 [CameraValue] 构建自定义的前景 widget
46+
///
47+
/// The [cameraValue] will be null until the [CameraController] initialized.
48+
/// 在 [CameraController] 完成初始化前,[cameraValue] 将为空。
4649
/// {@endtemplate}
4750
typedef ForegroundBuilder = Widget Function(
4851
BuildContext context,
49-
CameraValue cameraValue,
52+
CameraValue? cameraValue,
5053
);
5154

5255
/// {@template wechat_camera_picker.PreviewTransformBuilder}

lib/src/widgets/camera_picker.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import '../constants/config.dart';
1818
import '../constants/constants.dart';
1919
import '../constants/enums.dart';
2020
import '../constants/styles.dart';
21+
import '../constants/type_defs.dart';
2122
import '../delegates/camera_picker_text_delegate.dart';
2223
import '../internals/extensions.dart';
2324
import '../internals/methods.dart';
@@ -1323,18 +1324,10 @@ class CameraPickerState extends State<CameraPicker>
13231324
required BoxConstraints constraints,
13241325
}) {
13251326
return RepaintBoundary(
1326-
child: Stack(
1327-
children: <Widget>[
1328-
Positioned.fill(
1329-
child: _cameraPreview(
1330-
context,
1331-
orientation: value.deviceOrientation,
1332-
constraints: constraints,
1333-
),
1334-
),
1335-
if (config.foregroundBuilder != null)
1336-
Positioned.fill(child: config.foregroundBuilder!(context, value)),
1337-
],
1327+
child: _cameraPreview(
1328+
context,
1329+
orientation: value.deviceOrientation,
1330+
constraints: constraints,
13381331
),
13391332
);
13401333
}
@@ -1363,6 +1356,17 @@ class CameraPickerState extends State<CameraPicker>
13631356
);
13641357
}
13651358

1359+
Widget _foregroundBuilder(BuildContext context) {
1360+
final ForegroundBuilder builder = config.foregroundBuilder!;
1361+
if (_controller == null) {
1362+
return builder(context, null);
1363+
}
1364+
return ValueListenableBuilder<CameraValue>(
1365+
valueListenable: _controller!,
1366+
builder: (BuildContext c, CameraValue v, __) => builder(c, v),
1367+
);
1368+
}
1369+
13661370
@override
13671371
Widget build(BuildContext context) {
13681372
return AnnotatedRegion<SystemUiOverlayStyle>(
@@ -1393,6 +1397,8 @@ class CameraPickerState extends State<CameraPicker>
13931397
builder: (_, __) => _focusingAreaWidget(constraints),
13941398
),
13951399
_contentBuilder(constraints),
1400+
if (config.foregroundBuilder != null)
1401+
Positioned.fill(child: _foregroundBuilder(context)),
13961402
],
13971403
),
13981404
),

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
22
description: A camera picker which is an extension to wechat_assets_picker, but can be run separately.
3-
version: 3.2.0+1
3+
version: 3.2.1
44
homepage: https://github.com/fluttercandies/flutter_wechat_camera_picker
55

66
environment:

0 commit comments

Comments
 (0)