1.还原 UI 稿,地址和时间与录制按钮排版优化
This commit is contained in:
@@ -1,17 +1,16 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:recording_tool/core/utils/date_time_formatter.dart';
|
import 'package:recording_tool/core/utils/date_time_formatter.dart';
|
||||||
import 'package:recording_tool/features/recording/widgets/widget_recording_hint_chip.dart';
|
|
||||||
|
|
||||||
/// 显示剪贴板地址与实时时钟的提示芯片
|
/// 左下角实时时钟与剪贴板地址
|
||||||
class ClipboardAddressClockChipWidget extends StatefulWidget {
|
class ClipboardAddressClockChipWidget extends StatefulWidget {
|
||||||
const ClipboardAddressClockChipWidget({super.key, required this.address});
|
const ClipboardAddressClockChipWidget({super.key, required this.address});
|
||||||
|
|
||||||
final String address;
|
final String address;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 创建芯片状态
|
|
||||||
State<ClipboardAddressClockChipWidget> createState() =>
|
State<ClipboardAddressClockChipWidget> createState() =>
|
||||||
_ClipboardAddressClockChipWidgetState();
|
_ClipboardAddressClockChipWidgetState();
|
||||||
}
|
}
|
||||||
@@ -20,8 +19,14 @@ class _ClipboardAddressClockChipWidgetState
|
|||||||
extends State<ClipboardAddressClockChipWidget> {
|
extends State<ClipboardAddressClockChipWidget> {
|
||||||
Timer? _clockTimer;
|
Timer? _clockTimer;
|
||||||
|
|
||||||
|
static TextStyle get _textStyle => TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12.sp,
|
||||||
|
height: 1.4,
|
||||||
|
shadows: [Shadow(color: Colors.black54, blurRadius: 6.r)],
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 启动每秒刷新时钟
|
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||||
@@ -30,26 +35,27 @@ class _ClipboardAddressClockChipWidgetState
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 取消定时器
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_clockTimer?.cancel();
|
_clockTimer?.cancel();
|
||||||
_clockTimer = null;
|
_clockTimer = null;
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 拼接地址与当前时间文本
|
String get _nowText => DateTimeFormatter.format(
|
||||||
String _buildLabel() {
|
DateTime.now(),
|
||||||
final nowText = DateTimeFormatter.format(
|
pattern: 'yyyy-M-d-H:mm:ss',
|
||||||
DateTime.now(),
|
);
|
||||||
pattern: 'yyyy-M-d-H:mm:ss',
|
|
||||||
);
|
|
||||||
if (widget.address.isEmpty) return nowText;
|
|
||||||
return '${widget.address}\n$nowText';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 渲染时钟芯片
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RecordingHintChipWidget(label: _buildLabel(), onTap: () {});
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(_nowText, style: _textStyle),
|
||||||
|
if (widget.address.isNotEmpty)
|
||||||
|
Text(widget.address, style: _textStyle),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_clipboard_address_clock_chip.dart';
|
||||||
import 'package:recording_tool/features/recording/widgets/widget_recording_setup_hints.dart';
|
import 'package:recording_tool/features/recording/widgets/widget_recording_setup_hints.dart';
|
||||||
|
|
||||||
/// 录制页 HUD 层(状态提示、录制控制)
|
/// 录制页 HUD 层(状态提示、录制控制)
|
||||||
@@ -27,112 +28,120 @@ class RecordingHudWidget extends StatelessWidget {
|
|||||||
final VoidCallback onOpenBattery;
|
final VoidCallback onOpenBattery;
|
||||||
final VoidCallback onToggleTouchLock;
|
final VoidCallback onToggleTouchLock;
|
||||||
|
|
||||||
/// 底部控制区左右占位宽度
|
static double get _recordButtonSize => 70.r;
|
||||||
static double get _controlSlotWidth => 48.r;
|
static double get _recordButtonBottom => 63.r;
|
||||||
|
static double get _overlayInfoLeft => 13.r;
|
||||||
|
static double get _overlayInfoBottom => 10.r;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 构建 HUD 布局
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return Stack(
|
||||||
child: Column(
|
fit: StackFit.expand,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: 8.h),
|
Positioned(
|
||||||
const Spacer(),
|
left: 0,
|
||||||
if (state.errorMessage != null)
|
right: 0,
|
||||||
Padding(
|
top: 0,
|
||||||
padding: EdgeInsets.all(12.r),
|
bottom: _recordButtonBottom + _recordButtonSize + 16.h,
|
||||||
child: Text(
|
child: Column(
|
||||||
state.errorMessage!,
|
children: [
|
||||||
style: const TextStyle(color: Colors.amber),
|
SizedBox(height: 8.h),
|
||||||
textAlign: TextAlign.center,
|
const Spacer(),
|
||||||
),
|
if (state.errorMessage != null)
|
||||||
),
|
Padding(
|
||||||
if (state.permissionWarning != null)
|
padding: EdgeInsets.all(12.r),
|
||||||
Padding(
|
child: Text(
|
||||||
padding: EdgeInsets.symmetric(
|
state.errorMessage!,
|
||||||
horizontal: 16.r,
|
style: const TextStyle(color: Colors.amber),
|
||||||
vertical: 8.r,
|
textAlign: TextAlign.center,
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
state.permissionWarning!,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.orangeAccent,
|
|
||||||
fontSize: 12.sp,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
RecordingSetupHintsWidget(
|
|
||||||
hasDndAccess: state.hasDndAccess,
|
|
||||||
isBatteryIgnored: state.isBatteryOptimizedIgnored,
|
|
||||||
notificationsGranted: state.notificationsGranted,
|
|
||||||
showClipboardHint: showClipboardHint,
|
|
||||||
clipboardAddress: clipboardAddress,
|
|
||||||
onOpenDnd: onOpenDnd,
|
|
||||||
onOpenBattery: onOpenBattery,
|
|
||||||
onOpenNotificationSettings: openAppSettings,
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(24.r, 8.r, 24.r, 24.r),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: _controlSlotWidth,
|
|
||||||
height: _controlSlotWidth,
|
|
||||||
child: state.isRecording
|
|
||||||
? IconButton(
|
|
||||||
onPressed: onToggleTouchLock,
|
|
||||||
icon: Icon(
|
|
||||||
state.isTouchLocked ? Icons.lock : Icons.lock_open,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 28.r,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: state.isStartingRecording
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
if (state.isRecording) {
|
|
||||||
await onStop();
|
|
||||||
} else {
|
|
||||||
await onStart();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: 76.w,
|
|
||||||
height: 76.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
border: Border.all(
|
|
||||||
color: Colors.white,
|
|
||||||
width: 4.r,
|
|
||||||
),
|
|
||||||
color: state.isRecording ? Colors.white : Colors.red,
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
state.isRecording
|
|
||||||
? Icons.stop
|
|
||||||
: Icons.fiber_manual_record,
|
|
||||||
color: state.isRecording ? Colors.red : Colors.white,
|
|
||||||
size: 36.r,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
if (state.permissionWarning != null)
|
||||||
width: _controlSlotWidth,
|
Padding(
|
||||||
height: _controlSlotWidth,
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.r,
|
||||||
|
vertical: 8.r,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
state.permissionWarning!,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.orangeAccent,
|
||||||
|
fontSize: 12.sp,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
RecordingSetupHintsWidget(
|
||||||
|
hasDndAccess: state.hasDndAccess,
|
||||||
|
isBatteryIgnored: state.isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: state.notificationsGranted,
|
||||||
|
onOpenDnd: onOpenDnd,
|
||||||
|
onOpenBattery: onOpenBattery,
|
||||||
|
onOpenNotificationSettings: openAppSettings,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (showClipboardHint)
|
||||||
|
Positioned(
|
||||||
|
left: _overlayInfoLeft,
|
||||||
|
bottom: _overlayInfoBottom,
|
||||||
|
child: ClipboardAddressClockChipWidget(address: clipboardAddress),
|
||||||
|
),
|
||||||
|
if (state.isRecording)
|
||||||
|
Positioned(
|
||||||
|
left: 16.r,
|
||||||
|
bottom: _recordButtonBottom,
|
||||||
|
child: SizedBox(
|
||||||
|
height: _recordButtonSize,
|
||||||
|
child: Center(
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: onToggleTouchLock,
|
||||||
|
icon: Icon(
|
||||||
|
state.isTouchLocked ? Icons.lock : Icons.lock_open,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 28.r,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
Positioned(
|
||||||
),
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: _recordButtonBottom,
|
||||||
|
child: Center(
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: state.isStartingRecording
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
if (state.isRecording) {
|
||||||
|
await onStop();
|
||||||
|
} else {
|
||||||
|
await onStart();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
width: _recordButtonSize,
|
||||||
|
height: _recordButtonSize,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.white,
|
||||||
|
width: 4.r,
|
||||||
|
),
|
||||||
|
color: state.isRecording ? Colors.white : Colors.red,
|
||||||
|
),
|
||||||
|
child: Icon(
|
||||||
|
state.isRecording ? Icons.stop : Icons.fiber_manual_record,
|
||||||
|
color: state.isRecording ? Colors.red : Colors.white,
|
||||||
|
size: 32.r,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:recording_tool/features/recording/widgets/widget_clipboard_address_clock_chip.dart';
|
|
||||||
import 'package:recording_tool/features/recording/widgets/widget_recording_hint_chip.dart';
|
import 'package:recording_tool/features/recording/widgets/widget_recording_hint_chip.dart';
|
||||||
|
|
||||||
/// 权限与剪贴板相关设置提示条
|
/// 权限相关设置提示条
|
||||||
class RecordingSetupHintsWidget extends StatelessWidget {
|
class RecordingSetupHintsWidget extends StatelessWidget {
|
||||||
const RecordingSetupHintsWidget({
|
const RecordingSetupHintsWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.hasDndAccess,
|
required this.hasDndAccess,
|
||||||
required this.isBatteryIgnored,
|
required this.isBatteryIgnored,
|
||||||
required this.notificationsGranted,
|
required this.notificationsGranted,
|
||||||
this.showClipboardHint = false,
|
|
||||||
this.clipboardAddress = '',
|
|
||||||
required this.onOpenDnd,
|
required this.onOpenDnd,
|
||||||
required this.onOpenBattery,
|
required this.onOpenBattery,
|
||||||
required this.onOpenNotificationSettings,
|
required this.onOpenNotificationSettings,
|
||||||
@@ -20,19 +17,15 @@ class RecordingSetupHintsWidget extends StatelessWidget {
|
|||||||
final bool hasDndAccess;
|
final bool hasDndAccess;
|
||||||
final bool isBatteryIgnored;
|
final bool isBatteryIgnored;
|
||||||
final bool notificationsGranted;
|
final bool notificationsGranted;
|
||||||
final bool showClipboardHint;
|
|
||||||
final String clipboardAddress;
|
|
||||||
final VoidCallback onOpenDnd;
|
final VoidCallback onOpenDnd;
|
||||||
final VoidCallback onOpenBattery;
|
final VoidCallback onOpenBattery;
|
||||||
final VoidCallback onOpenNotificationSettings;
|
final VoidCallback onOpenNotificationSettings;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/// 按需展示权限/剪贴板提示
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final showPermissionHints =
|
final showPermissionHints =
|
||||||
!hasDndAccess || !isBatteryIgnored || !notificationsGranted;
|
!hasDndAccess || !isBatteryIgnored || !notificationsGranted;
|
||||||
final showClipboardHint = this.showClipboardHint;
|
if (!showPermissionHints) {
|
||||||
if (!showPermissionHints && !showClipboardHint) {
|
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +41,7 @@ class RecordingSetupHintsWidget extends StatelessWidget {
|
|||||||
SizedBox(height: 8.h),
|
SizedBox(height: 8.h),
|
||||||
],
|
],
|
||||||
if (!hasDndAccess)
|
if (!hasDndAccess)
|
||||||
RecordingHintChipWidget(
|
RecordingHintChipWidget(label: '开启勿扰权限可减少录制中断', onTap: onOpenDnd),
|
||||||
label: '开启勿扰权限可减少录制中断',
|
|
||||||
onTap: onOpenDnd,
|
|
||||||
),
|
|
||||||
if (!isBatteryIgnored) ...[
|
if (!isBatteryIgnored) ...[
|
||||||
SizedBox(height: 8.h),
|
SizedBox(height: 8.h),
|
||||||
RecordingHintChipWidget(
|
RecordingHintChipWidget(
|
||||||
@@ -59,10 +49,6 @@ class RecordingSetupHintsWidget extends StatelessWidget {
|
|||||||
onTap: onOpenBattery,
|
onTap: onOpenBattery,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (showClipboardHint) ...[
|
|
||||||
SizedBox(height: 8.h),
|
|
||||||
ClipboardAddressClockChipWidget(address: clipboardAddress),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user