实现缩放功能:增加缩放功能检索和设置方法,更新UI以支持缩放调整,增强缩放比例的状态管理。
This commit is contained in:
@@ -11,6 +11,9 @@ class RecordingSessionState {
|
||||
this.isBatteryOptimizedIgnored = true,
|
||||
this.notificationsGranted = true,
|
||||
this.isMicrophoneGranted = false,
|
||||
this.zoomRatio = 1.0,
|
||||
this.minZoomRatio = 1.0,
|
||||
this.maxZoomRatio = 3.0,
|
||||
this.lastOutputPath,
|
||||
this.lastSavedDisplayName,
|
||||
this.errorMessage,
|
||||
@@ -26,6 +29,9 @@ class RecordingSessionState {
|
||||
final bool isBatteryOptimizedIgnored;
|
||||
final bool notificationsGranted;
|
||||
final bool isMicrophoneGranted;
|
||||
final double zoomRatio;
|
||||
final double minZoomRatio;
|
||||
final double maxZoomRatio;
|
||||
final String? lastOutputPath;
|
||||
final String? lastSavedDisplayName;
|
||||
final String? errorMessage;
|
||||
@@ -51,6 +57,9 @@ class RecordingSessionState {
|
||||
bool? isBatteryOptimizedIgnored,
|
||||
bool? notificationsGranted,
|
||||
bool? isMicrophoneGranted,
|
||||
double? zoomRatio,
|
||||
double? minZoomRatio,
|
||||
double? maxZoomRatio,
|
||||
String? lastOutputPath,
|
||||
String? lastSavedDisplayName,
|
||||
String? errorMessage,
|
||||
@@ -69,6 +78,9 @@ class RecordingSessionState {
|
||||
isBatteryOptimizedIgnored ?? this.isBatteryOptimizedIgnored,
|
||||
notificationsGranted: notificationsGranted ?? this.notificationsGranted,
|
||||
isMicrophoneGranted: isMicrophoneGranted ?? this.isMicrophoneGranted,
|
||||
zoomRatio: zoomRatio ?? this.zoomRatio,
|
||||
minZoomRatio: minZoomRatio ?? this.minZoomRatio,
|
||||
maxZoomRatio: maxZoomRatio ?? this.maxZoomRatio,
|
||||
lastOutputPath: lastOutputPath ?? this.lastOutputPath,
|
||||
lastSavedDisplayName: clearLastSaved
|
||||
? null
|
||||
|
||||
@@ -357,10 +357,7 @@ class _PreviewLoadingLayer extends ConsumerWidget {
|
||||
}
|
||||
|
||||
class _RecordingHudLayer extends ConsumerWidget {
|
||||
const _RecordingHudLayer({
|
||||
required this.onStart,
|
||||
required this.onStop,
|
||||
});
|
||||
const _RecordingHudLayer({required this.onStart, required this.onStop});
|
||||
|
||||
final Future<void> Function() onStart;
|
||||
final Future<void> Function() onStop;
|
||||
@@ -378,6 +375,9 @@ class _RecordingHudLayer extends ConsumerWidget {
|
||||
m.session.isRecording,
|
||||
m.session.isStartingRecording,
|
||||
m.session.isTouchLocked,
|
||||
m.session.zoomRatio,
|
||||
m.session.minZoomRatio,
|
||||
m.session.maxZoomRatio,
|
||||
m.hasValidClipboardInfo,
|
||||
m.clipboardRecordingModel.address.trim(),
|
||||
),
|
||||
@@ -392,6 +392,9 @@ class _RecordingHudLayer extends ConsumerWidget {
|
||||
isRecording,
|
||||
isStartingRecording,
|
||||
isTouchLocked,
|
||||
zoomRatio,
|
||||
minZoomRatio,
|
||||
maxZoomRatio,
|
||||
showClipboardHint,
|
||||
clipboardAddress,
|
||||
) = hudState;
|
||||
@@ -406,6 +409,9 @@ class _RecordingHudLayer extends ConsumerWidget {
|
||||
isRecording: isRecording,
|
||||
isStartingRecording: isStartingRecording,
|
||||
isTouchLocked: isTouchLocked,
|
||||
zoomRatio: zoomRatio,
|
||||
minZoomRatio: minZoomRatio,
|
||||
maxZoomRatio: maxZoomRatio,
|
||||
showClipboardHint: showClipboardHint,
|
||||
clipboardAddress: clipboardAddress,
|
||||
onStart: onStart,
|
||||
@@ -419,9 +425,15 @@ class _RecordingHudLayer extends ConsumerWidget {
|
||||
await viewModel.refreshBatteryOptimization();
|
||||
},
|
||||
onToggleTouchLock: () {
|
||||
final locked = ref.read(recordingViewModelProvider).session.isTouchLocked;
|
||||
final locked = ref
|
||||
.read(recordingViewModelProvider)
|
||||
.session
|
||||
.isTouchLocked;
|
||||
viewModel.setTouchLocked(!locked);
|
||||
},
|
||||
onZoomSelected: (ratio) async {
|
||||
await viewModel.setZoomRatio(ratio);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,21 @@ class RecordingPlatform {
|
||||
return RecordingStatus.fromMap(result ?? const {});
|
||||
}
|
||||
|
||||
static Future<RecordingZoomCapabilities> getZoomCapabilities() async {
|
||||
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||
'getZoomCapabilities',
|
||||
);
|
||||
return RecordingZoomCapabilities.fromMap(result);
|
||||
}
|
||||
|
||||
static Future<RecordingZoomCapabilities> setZoomRatio(double ratio) async {
|
||||
final result = await _channel.invokeMapMethod<String, dynamic>(
|
||||
'setZoomRatio',
|
||||
<String, dynamic>{'zoomRatio': ratio},
|
||||
);
|
||||
return RecordingZoomCapabilities.fromMap(result);
|
||||
}
|
||||
|
||||
static Future<RecordingStartResult> startRecording({
|
||||
bool withAudio = true,
|
||||
bool enableDoNotDisturb = true,
|
||||
@@ -156,6 +171,29 @@ class RecordingPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
class RecordingZoomCapabilities {
|
||||
const RecordingZoomCapabilities({
|
||||
required this.zoomRatio,
|
||||
required this.minZoomRatio,
|
||||
required this.maxZoomRatio,
|
||||
});
|
||||
|
||||
final double zoomRatio;
|
||||
final double minZoomRatio;
|
||||
final double maxZoomRatio;
|
||||
|
||||
factory RecordingZoomCapabilities.fromMap(Map<String, dynamic>? map) {
|
||||
final minZoomRatio = (map?['minZoomRatio'] as num?)?.toDouble() ?? 1.0;
|
||||
final maxZoomRatio = (map?['maxZoomRatio'] as num?)?.toDouble() ?? 3.0;
|
||||
final zoomRatio = (map?['zoomRatio'] as num?)?.toDouble() ?? minZoomRatio;
|
||||
return RecordingZoomCapabilities(
|
||||
zoomRatio: zoomRatio.clamp(minZoomRatio, maxZoomRatio).toDouble(),
|
||||
minZoomRatio: minZoomRatio,
|
||||
maxZoomRatio: maxZoomRatio,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecordingStartResult {
|
||||
const RecordingStartResult({this.outputPath, required this.status});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -170,7 +170,7 @@ class _HeaderPasteActions extends StatelessWidget {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
// _HeaderActionButton(label: 'mock', onPressed: onMockCopy),
|
||||
_HeaderActionButton(label: 'mock', onPressed: onMockCopy),
|
||||
_HeaderActionButton(
|
||||
label: '粘贴选手信息',
|
||||
onPressed: () => onPasteEventInfo(),
|
||||
|
||||
@@ -21,11 +21,15 @@ class RecordingHudWidget extends StatelessWidget {
|
||||
required this.isTouchLocked,
|
||||
this.showClipboardHint = false,
|
||||
this.clipboardAddress = '',
|
||||
required this.zoomRatio,
|
||||
required this.minZoomRatio,
|
||||
required this.maxZoomRatio,
|
||||
required this.onStart,
|
||||
required this.onStop,
|
||||
required this.onOpenDnd,
|
||||
required this.onOpenBattery,
|
||||
required this.onToggleTouchLock,
|
||||
required this.onZoomSelected,
|
||||
});
|
||||
|
||||
final String? errorMessage;
|
||||
@@ -38,16 +42,21 @@ class RecordingHudWidget extends StatelessWidget {
|
||||
final bool isTouchLocked;
|
||||
final bool showClipboardHint;
|
||||
final String clipboardAddress;
|
||||
final double zoomRatio;
|
||||
final double minZoomRatio;
|
||||
final double maxZoomRatio;
|
||||
final Future<void> Function() onStart;
|
||||
final Future<void> Function() onStop;
|
||||
final VoidCallback onOpenDnd;
|
||||
final VoidCallback onOpenBattery;
|
||||
final VoidCallback onToggleTouchLock;
|
||||
final ValueChanged<double> onZoomSelected;
|
||||
|
||||
static double get _recordButtonSize => 70.r;
|
||||
static double get _recordButtonBottom => 63.r;
|
||||
static double get _overlayInfoLeft => 13.r;
|
||||
static double get _overlayInfoBottom => 10.r;
|
||||
static const List<double> _zoomPresets = [1.0, 2.0, 3.0];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -133,6 +142,17 @@ class RecordingHudWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 16.r,
|
||||
bottom: _recordButtonBottom + _recordButtonSize + 14.h,
|
||||
child: _ZoomPresetControl(
|
||||
zoomRatio: zoomRatio,
|
||||
minZoomRatio: minZoomRatio,
|
||||
maxZoomRatio: maxZoomRatio,
|
||||
presets: _zoomPresets,
|
||||
onSelected: onZoomSelected,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
@@ -171,3 +191,94 @@ class RecordingHudWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ZoomPresetControl extends StatelessWidget {
|
||||
const _ZoomPresetControl({
|
||||
required this.zoomRatio,
|
||||
required this.minZoomRatio,
|
||||
required this.maxZoomRatio,
|
||||
required this.presets,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final double zoomRatio;
|
||||
final double minZoomRatio;
|
||||
final double maxZoomRatio;
|
||||
final List<double> presets;
|
||||
final ValueChanged<double> onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final availablePresets = presets
|
||||
.where((preset) => preset >= minZoomRatio && preset <= maxZoomRatio)
|
||||
.toList(growable: false);
|
||||
|
||||
if (availablePresets.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.46),
|
||||
borderRadius: BorderRadius.circular(18.r),
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.18)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(3.r),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final preset in availablePresets)
|
||||
_ZoomPresetButton(
|
||||
ratio: preset,
|
||||
selected: (zoomRatio - preset).abs() < 0.05,
|
||||
onSelected: onSelected,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ZoomPresetButton extends StatelessWidget {
|
||||
const _ZoomPresetButton({
|
||||
required this.ratio,
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final double ratio;
|
||||
final bool selected;
|
||||
final ValueChanged<double> onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 1.r),
|
||||
child: TextButton(
|
||||
onPressed: selected ? null : () => onSelected(ratio),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: Size(38.r, 32.r),
|
||||
padding: EdgeInsets.zero,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
foregroundColor: selected ? Colors.black : Colors.white,
|
||||
disabledForegroundColor: Colors.black,
|
||||
backgroundColor: selected ? Colors.white : Colors.transparent,
|
||||
disabledBackgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(15.r),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'${ratio.toStringAsFixed(0)}x',
|
||||
style: TextStyle(
|
||||
fontSize: 13.sp,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user