Skip to content

Commit

Permalink
🚸 Trigger shooting preparation only when start recording on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Aug 18, 2021
1 parent 301aee7 commit 3d8093f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/src/widget/camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ class CameraPickerState extends State<CameraPicker>
/// 通过常量全局 Key 获取当前选择器的主题
ThemeData get theme => _theme;

bool _isPreparedForIOSRecording = false;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -783,8 +785,12 @@ class CameraPickerState extends State<CameraPicker>

/// Set record file path and start recording.
/// 设置拍摄文件路径并开始录制视频
void startRecordingVideo() {
Future<void> startRecordingVideo() async {
if (!controller.value.isRecordingVideo) {
if (!_isPreparedForIOSRecording) {
await controller.prepareForVideoRecording();
_isPreparedForIOSRecording = true;
}
controller.startVideoRecording().then((dynamic _) {
safeSetState(() {});
if (isRecordingRestricted) {
Expand Down Expand Up @@ -986,9 +992,6 @@ class CameraPickerState extends State<CameraPicker>
const Size innerSize = Size.square(82);
return Listener(
behavior: HitTestBehavior.opaque,
onPointerDown: shouldPrepareForVideoRecording
? (_) => controller.prepareForVideoRecording()
: null,
onPointerUp: enableRecording ? recordDetectionCancel : null,
onPointerMove: enablePullToZoomInRecord
? (PointerMoveEvent e) => onShootingButtonMove(e, constraints)
Expand Down

0 comments on commit 3d8093f

Please sign in to comment.