Skip to content

Commit 89bb14e

Browse files
committed
✨ Add isOnlyAllowRecording .
Resolves #4 .
1 parent b3837ad commit 89bb14e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ class CameraPicker extends StatefulWidget {
3030
CameraPicker({
3131
Key key,
3232
this.isAllowRecording = false,
33+
this.isOnlyAllowRecording = false,
3334
this.maximumRecordingDuration = const Duration(seconds: 15),
3435
this.theme,
3536
CameraPickerTextDelegate textDelegate,
36-
}) : super(key: key) {
37+
}) : assert(
38+
isAllowRecording == true || isOnlyAllowRecording != true,
39+
'Recording mode error.',
40+
),
41+
super(key: key) {
3742
Constants.textDelegate = textDelegate ??
3843
(isAllowRecording
3944
? DefaultCameraPickerTextDelegateWithRecording()
@@ -44,6 +49,10 @@ class CameraPicker extends StatefulWidget {
4449
/// 选择器是否可以录像
4550
final bool isAllowRecording;
4651

52+
/// Whether the picker can record video.
53+
/// 选择器是否可以录像
54+
final bool isOnlyAllowRecording;
55+
4756
/// The maximum duration of the video recording process.
4857
/// 录制视频最长时长
4958
///
@@ -60,17 +69,22 @@ class CameraPicker extends StatefulWidget {
6069
static Future<AssetEntity> pickFromCamera(
6170
BuildContext context, {
6271
bool isAllowRecording = false,
72+
bool isOnlyAllowRecording = false,
6373
Duration maximumRecordingDuration = const Duration(seconds: 15),
6474
ThemeData theme,
6575
CameraPickerTextDelegate textDelegate,
6676
}) async {
77+
if (isAllowRecording != true && isOnlyAllowRecording == true) {
78+
throw ArgumentError('Recording mode error.');
79+
}
6780
final AssetEntity result = await Navigator.of(
6881
context,
6982
rootNavigator: true,
7083
).push<AssetEntity>(
7184
SlidePageTransitionBuilder<AssetEntity>(
7285
builder: CameraPicker(
7386
isAllowRecording: isAllowRecording,
87+
isOnlyAllowRecording: isOnlyAllowRecording,
7488
theme: theme,
7589
textDelegate: textDelegate,
7690
),
@@ -193,6 +207,10 @@ class CameraPickerState extends State<CameraPicker> {
193207
/// 选择器是否可以录像(非空包装)
194208
bool get isAllowRecording => widget.isAllowRecording ?? false;
195209

210+
/// Whether the picker can only record video. (A non-null wrapper)
211+
/// 选择器是否仅可以录像(非空包装)
212+
bool get isOnlyAllowRecording => widget.isOnlyAllowRecording ?? false;
213+
196214
/// Getter for `widget.maximumRecordingDuration` .
197215
Duration get maximumRecordingDuration => widget.maximumRecordingDuration;
198216

@@ -597,7 +615,7 @@ class CameraPickerState extends State<CameraPicker> {
597615
onPointerUp: isAllowRecording ? recordDetectionCancel : null,
598616
child: InkWell(
599617
borderRadius: maxBorderRadius,
600-
onTap: takePicture,
618+
onTap: !isOnlyAllowRecording ? takePicture : null,
601619
onLongPress: isAllowRecording ? recordDetection : null,
602620
child: SizedBox.fromSize(
603621
size: outerSize,

0 commit comments

Comments
 (0)