Skip to content

Commit 408f0d1

Browse files
committed
🚀 Expose resolution preset control.
1 parent cd866c6 commit 408f0d1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ class CameraPicker extends StatefulWidget {
3333
this.isOnlyAllowRecording = false,
3434
this.maximumRecordingDuration = const Duration(seconds: 15),
3535
this.theme,
36+
this.resolutionPreset = ResolutionPreset.max,
3637
CameraPickerTextDelegate textDelegate,
3738
}) : assert(
3839
isAllowRecording == true || isOnlyAllowRecording != true,
3940
'Recording mode error.',
4041
),
42+
assert(
43+
resolutionPreset != null,
44+
'Resolution preset must not be null.',
45+
),
4146
super(key: key) {
4247
Constants.textDelegate = textDelegate ??
4348
(isAllowRecording
@@ -64,6 +69,10 @@ class CameraPicker extends StatefulWidget {
6469
/// 选择器的主题
6570
final ThemeData theme;
6671

72+
/// Present resolution for the camera.
73+
/// 相机的分辨率预设
74+
final ResolutionPreset resolutionPreset;
75+
6776
/// Static method to create [AssetEntity] through camera.
6877
/// 通过相机创建 [AssetEntity] 的静态方法
6978
static Future<AssetEntity> pickFromCamera(
@@ -73,10 +82,14 @@ class CameraPicker extends StatefulWidget {
7382
Duration maximumRecordingDuration = const Duration(seconds: 15),
7483
ThemeData theme,
7584
CameraPickerTextDelegate textDelegate,
85+
ResolutionPreset resolutionPreset = ResolutionPreset.max,
7686
}) async {
7787
if (isAllowRecording != true && isOnlyAllowRecording == true) {
7888
throw ArgumentError('Recording mode error.');
7989
}
90+
if (resolutionPreset == null) {
91+
throw ArgumentError('Resolution preset must not be null.');
92+
}
8093
final AssetEntity result = await Navigator.of(
8194
context,
8295
rootNavigator: true,
@@ -87,6 +100,7 @@ class CameraPicker extends StatefulWidget {
87100
isOnlyAllowRecording: isOnlyAllowRecording,
88101
theme: theme,
89102
textDelegate: textDelegate,
103+
resolutionPreset: resolutionPreset,
90104
),
91105
transitionCurve: Curves.easeIn,
92106
transitionDuration: const Duration(milliseconds: 300),
@@ -348,7 +362,7 @@ class CameraPickerState extends State<CameraPicker> {
348362
/// - No one want the lower resolutions. :)
349363
cameraController = CameraController(
350364
cameraDescription ?? cameras[0],
351-
ResolutionPreset.max,
365+
widget.resolutionPreset,
352366
);
353367
cameraController.initialize().then((dynamic _) {
354368
if (mounted) {

lib/wechat_camera_picker.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library wechat_camera_picker;
22

3+
export 'package:camera/camera.dart' show ResolutionPreset;
34
export 'package:photo_manager/photo_manager.dart';
45

56
export 'src/delegates/camera_picker_text_delegate.dart';

0 commit comments

Comments
 (0)