实现缩放功能:增加缩放功能检索和设置方法,更新UI以支持缩放调整,增强缩放比例的状态管理。
This commit is contained in:
@@ -193,6 +193,7 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
||||
await _listenStatus();
|
||||
try {
|
||||
final status = await _initializePreviewWithRetry();
|
||||
await _refreshZoomCapabilities();
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
status: status,
|
||||
@@ -239,6 +240,7 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
||||
);
|
||||
try {
|
||||
final status = await _initializePreviewWithRetry();
|
||||
await _refreshZoomCapabilities();
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
status: status,
|
||||
@@ -309,6 +311,47 @@ class RecordingViewModel extends Notifier<RecordingModel> {
|
||||
return status?.isGranted == true || status?.isLimited == true;
|
||||
}
|
||||
|
||||
/// 读取相机支持的倍距范围并同步当前倍距。
|
||||
Future<void> _refreshZoomCapabilities() async {
|
||||
try {
|
||||
final zoom = await RecordingPlatform.getZoomCapabilities();
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
zoomRatio: zoom.zoomRatio,
|
||||
minZoomRatio: zoom.minZoomRatio,
|
||||
maxZoomRatio: zoom.maxZoomRatio,
|
||||
errorMessage: null,
|
||||
),
|
||||
);
|
||||
} on PlatformException catch (error) {
|
||||
AppLogger.debug('读取相机倍距能力失败', error: error);
|
||||
}
|
||||
}
|
||||
|
||||
/// 设置相机倍距,原生层会返回设备实际应用后的倍距范围与当前值。
|
||||
Future<void> setZoomRatio(double ratio) async {
|
||||
final session = state.session;
|
||||
final clamped = ratio
|
||||
.clamp(session.minZoomRatio, session.maxZoomRatio)
|
||||
.toDouble();
|
||||
|
||||
try {
|
||||
final zoom = await RecordingPlatform.setZoomRatio(clamped);
|
||||
_updateSession(
|
||||
(s) => s.copyWith(
|
||||
zoomRatio: zoom.zoomRatio,
|
||||
minZoomRatio: zoom.minZoomRatio,
|
||||
maxZoomRatio: zoom.maxZoomRatio,
|
||||
errorMessage: null,
|
||||
),
|
||||
);
|
||||
} on PlatformException catch (error) {
|
||||
_updateSession(
|
||||
(s) => s.copyWith(errorMessage: error.message ?? '相机倍距设置失败'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 开始录制,可选开启勿扰模式。
|
||||
Future<void> startRecording({bool enableDoNotDisturb = true}) async {
|
||||
final session = state.session;
|
||||
|
||||
Reference in New Issue
Block a user