优化录制页面的相机预览逻辑,增加预览未就绪时的错误提示,确保用户体验更流畅。
This commit is contained in:
@@ -135,7 +135,13 @@ class _RecordingPageState extends ConsumerState<RecordingPage> {
|
|||||||
final result = await ref
|
final result = await ref
|
||||||
.read(recordingViewModelProvider.notifier)
|
.read(recordingViewModelProvider.notifier)
|
||||||
.ensureCameraAndMicrophonePermissions();
|
.ensureCameraAndMicrophonePermissions();
|
||||||
if (result.allGranted) return true;
|
if (result.allGranted) {
|
||||||
|
final ready = ref.read(recordingViewModelProvider).session.isPreviewReady;
|
||||||
|
if (ready) return true;
|
||||||
|
if (!mounted) return false;
|
||||||
|
AppToast.show('相机预览启动失败,请重试');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!mounted) return false;
|
if (!mounted) return false;
|
||||||
|
|
||||||
await RecordDialog.showSingle(
|
await RecordDialog.showSingle(
|
||||||
|
|||||||
@@ -280,6 +280,12 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
|||||||
|
|
||||||
_updateSession((s) => s.copyWith(isMicrophoneGranted: microphoneGranted));
|
_updateSession((s) => s.copyWith(isMicrophoneGranted: microphoneGranted));
|
||||||
|
|
||||||
|
if (cameraGranted && !state.session.isPreviewReady) {
|
||||||
|
_updateSession((s) => s.copyWith(errorMessage: null));
|
||||||
|
await _listenStatus();
|
||||||
|
await restorePreview();
|
||||||
|
}
|
||||||
|
|
||||||
return RecordingRequiredPermissions(
|
return RecordingRequiredPermissions(
|
||||||
cameraGranted: cameraGranted,
|
cameraGranted: cameraGranted,
|
||||||
microphoneGranted: microphoneGranted,
|
microphoneGranted: microphoneGranted,
|
||||||
@@ -293,9 +299,13 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
|||||||
/// 开始录制,可选开启勿扰模式。
|
/// 开始录制,可选开启勿扰模式。
|
||||||
Future<void> startRecording({bool enableDoNotDisturb = true}) async {
|
Future<void> startRecording({bool enableDoNotDisturb = true}) async {
|
||||||
final session = state.session;
|
final session = state.session;
|
||||||
if (!session.isPreviewReady ||
|
if (session.isRecording || session.isStartingRecording) {
|
||||||
session.isRecording ||
|
return;
|
||||||
session.isStartingRecording) {
|
}
|
||||||
|
if (!session.isPreviewReady) {
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(errorMessage: '相机预览未就绪,请稍后重试'),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user