Skip to content

Commit 5603bc6

Browse files
authored
support set enableAudio attr (#17)
1 parent 7455d05 commit 5603bc6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CameraPicker extends StatefulWidget {
3131
Key key,
3232
this.isAllowRecording = false,
3333
this.isOnlyAllowRecording = false,
34+
this.enableAudio = true,
3435
this.maximumRecordingDuration = const Duration(seconds: 15),
3536
this.theme,
3637
this.resolutionPreset = ResolutionPreset.max,
@@ -63,6 +64,10 @@ class CameraPicker extends StatefulWidget {
6364
/// 选择器是否可以录像
6465
final bool isOnlyAllowRecording;
6566

67+
/// Whether the picker should record audio.
68+
/// 选择器录像时是否需要录制声音
69+
final bool enableAudio;
70+
6671
/// The maximum duration of the video recording process.
6772
/// 录制视频最长时长
6873
///
@@ -84,6 +89,7 @@ class CameraPicker extends StatefulWidget {
8489
BuildContext context, {
8590
bool isAllowRecording = false,
8691
bool isOnlyAllowRecording = false,
92+
bool enableAudio = true,
8793
Duration maximumRecordingDuration = const Duration(seconds: 15),
8894
ThemeData theme,
8995
int cameraQuarterTurns = 0,
@@ -104,6 +110,7 @@ class CameraPicker extends StatefulWidget {
104110
builder: CameraPicker(
105111
isAllowRecording: isAllowRecording,
106112
isOnlyAllowRecording: isOnlyAllowRecording,
113+
enableAudio: enableAudio,
107114
maximumRecordingDuration: maximumRecordingDuration,
108115
theme: theme,
109116
cameraQuarterTurns: cameraQuarterTurns,
@@ -233,6 +240,10 @@ class CameraPickerState extends State<CameraPicker> {
233240
/// 选择器是否仅可以录像(非空包装)
234241
bool get isOnlyAllowRecording => widget.isOnlyAllowRecording ?? false;
235242

243+
/// Whether the picker should record audio. (A non-null wrapper)
244+
/// 选择器录制视频时,是否需要录制音频(非空包装)
245+
bool get enableAudio => isAllowRecording && (widget.enableAudio ?? true);
246+
236247
/// Getter for `widget.maximumRecordingDuration` .
237248
Duration get maximumRecordingDuration => widget.maximumRecordingDuration;
238249

@@ -371,6 +382,7 @@ class CameraPickerState extends State<CameraPicker> {
371382
cameraController = CameraController(
372383
cameraDescription ?? cameras[0],
373384
widget.resolutionPreset,
385+
enableAudio: enableAudio,
374386
);
375387
cameraController.initialize().then((dynamic _) {
376388
if (mounted) {

0 commit comments

Comments
 (0)