完成远程遥控页面的优化,包括 折叠功能栏 点击振动反馈 ,急停的读秒进度条 ,左右的振动反馈 ,锁屏的功能按钮的开发(禁用上下左右的滑轮)

This commit is contained in:
2026-03-24 17:09:12 +08:00
parent f7523a943d
commit 8772b1cb43
17 changed files with 525 additions and 119 deletions

View File

@@ -17,7 +17,7 @@ class EmergencyStopButton extends StatefulWidget {
}
class _EmergencyStopButtonState extends State<EmergencyStopButton>
with TickerProviderStateMixin {
with SingleTickerProviderStateMixin {
late AnimationController _progressController;
bool _isPressing = false;
@@ -28,6 +28,13 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
vsync: this,
duration: const Duration(seconds: 3),
);
// 添加监听器,确保动画值变化时重建 UI
_progressController.addListener(() {
if (mounted) {
setState(() {});
}
});
}
@override
@@ -36,94 +43,118 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
super.dispose();
}
void _resetProgress() {
setState(() => _isPressing = false);
_progressController.stop();
_progressController.value = 0;
}
@override
Widget build(BuildContext context) {
// 监听 Cubit 中的急停状态
final isEmergencyActive = context
.watch<RemoteControlCubit>()
.state
.isEmergency;
final width = widget.width * 0.65;
final double indicatorSize = width + 10;
final double indicatorSize = width + 20;
return GestureDetector(
// 1. 处理点击:仅在未急停时触发
onTap: () {
if (!isEmergencyActive) {
context.read<RemoteControlCubit>().updateEmergency(true);
HapticFeedback.heavyImpact(); // 震动反馈
}
},
// 2. 处理长按开始:仅在已急停时触发解除逻辑
onLongPressStart: (_) {
if (isEmergencyActive) {
setState(() => _isPressing = true);
_progressController.forward(from: 0).then((_) {
if (_isPressing) {
// 进度走完且仍在按压
context.read<RemoteControlCubit>().updateEmergency(false);
HapticFeedback.vibrate();
setState(() => _isPressing = false);
}
});
}
},
// 3. 处理松手:重置进度
onLongPressEnd: (_) {
_isPressing = false;
_progressController.stop();
_progressController.value = 0;
setState(() {});
},
return SizedBox(
width: indicatorSize,
height: indicatorSize,
child: Stack(
alignment: Alignment.center,
children: [
// 对应 Compose 的 Canvas 绘制进度环
if (_isPressing)
SizedBox(
// 进度环 - 只在按压时显示
AnimatedOpacity(
opacity: _isPressing ? 1.0 : 0.0,
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: indicatorSize,
height: indicatorSize,
child: CircularProgressIndicator(
value: _progressController.value,
strokeWidth: 10,
color: Colors.red.withOpacity(0.8),
strokeWidth: 6,
color: Colors.red.withOpacity(0.9),
backgroundColor: Colors.red.withValues(alpha: 0.2),
),
),
),
Container(
width: width,
height: width,
decoration: BoxDecoration(
shape: BoxShape.circle,
// 根据状态切换颜色,对应 Color(0x80C53030)
color: isEmergencyActive
? Colors.red.withOpacity(0.5)
: const Color(0x80C53030),
boxShadow: isEmergencyActive
? [
BoxShadow(
color: Colors.red.withValues(alpha: 0.5),
blurRadius: 20,
),
]
: [],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset('assets/svgs/remote_alert.svg',width: width * 0.4,color: Colors.white.withValues(alpha: 0.5),),
const SizedBox(height: 6),
Text(
isEmergencyActive ? "急停中" : "急停",
style: TextStyle(
color: Colors.white.withValues(alpha: 0.5),
fontSize: 14,
fontWeight: FontWeight.w900,
// 按钮主体
GestureDetector(
onTap: () {
debugPrint('🔴 [点击] 触发急停');
if (!isEmergencyActive) {
context.read<RemoteControlCubit>().updateEmergency(true);
HapticFeedback.heavyImpact();
}
},
onLongPressStart: (_) {
debugPrint('🔴 [长按开始] isEmergency=$isEmergencyActive');
if (isEmergencyActive && !_isPressing) {
setState(() => _isPressing = true);
debugPrint('🔴 [开始动画] 从 0 开始');
_progressController.reset();
_progressController.forward().then((_) {
debugPrint('🔴 [动画完成] _isPressing=$_isPressing');
if (_isPressing && mounted) {
debugPrint('✅ [解除急停] 执行');
context.read<RemoteControlCubit>().updateEmergency(false);
HapticFeedback.vibrate();
setState(() => _isPressing = false);
}
});
}
},
onLongPressEnd: (_) {
debugPrint('🔴 [长按结束]');
if (_isPressing) {
_resetProgress();
}
},
onLongPressCancel: () {
debugPrint('🔴 [长按取消]');
if (_isPressing) {
_resetProgress();
}
},
child: Container(
width: width,
height: width,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isEmergencyActive
? Colors.red.withOpacity(0.5)
: const Color(0x80C53030),
boxShadow: isEmergencyActive
? [
BoxShadow(
color: Colors.red.withValues(alpha: 0.5),
blurRadius: 20,
),
),
],
]
: [],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
'assets/svgs/remote_alert.svg',
width: width * 0.4,
color: Colors.white.withValues(alpha: 0.5),
),
const SizedBox(height: 6),
Text(
isEmergencyActive ? "急停中" : "急停",
style: TextStyle(
color: Colors.white.withValues(alpha: 0.5),
fontSize: 14,
fontWeight: FontWeight.w900,
),
),
],
),
),
),
],