From 9d25b305d8160ebf74ec7c38b67598d50be8fe91 Mon Sep 17 00:00:00 2001 From: Songzex <2402265378@qq.com> Date: Wed, 25 Mar 2026 16:42:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=80=A5=E5=81=9C=E7=9A=84?= =?UTF-8?q?=E6=8C=AF=E5=8A=A8=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/remote_control_page.dart | 10 +++++++- .../widgets/emergency_stop_button.dart | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/features/remote_control/presentation/pages/remote_control_page.dart b/lib/features/remote_control/presentation/pages/remote_control_page.dart index 6f3da642..a2400c20 100644 --- a/lib/features/remote_control/presentation/pages/remote_control_page.dart +++ b/lib/features/remote_control/presentation/pages/remote_control_page.dart @@ -27,6 +27,13 @@ class RemoteControlPage extends StatefulWidget { class _RemoteControlPageState extends State { String _videoStreamUrl = ""; + late RemoteControlCubit _cubit; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _cubit = context.read(); + } @override void initState() { super.initState(); @@ -48,7 +55,8 @@ class _RemoteControlPageState extends State { void dispose() { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); - context.read().stopControlLoop(); + // context.read().stopControlLoop(); + _cubit.stopControlLoop(); super.dispose(); } diff --git a/lib/features/remote_control/presentation/widgets/emergency_stop_button.dart b/lib/features/remote_control/presentation/widgets/emergency_stop_button.dart index c00ba6e9..34f9b0ec 100644 --- a/lib/features/remote_control/presentation/widgets/emergency_stop_button.dart +++ b/lib/features/remote_control/presentation/widgets/emergency_stop_button.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:vibration/vibration.dart'; import '../bloc/remote_control_cubit.dart'; @@ -49,6 +50,8 @@ class _EmergencyStopButtonState extends State _progressController.value = 0; } + + @override Widget build(BuildContext context) { final isEmergencyActive = context @@ -85,22 +88,28 @@ class _EmergencyStopButtonState extends State GestureDetector( onTap: () { debugPrint('🔴 [点击] 触发急停'); + _triggerVibration(); if (!isEmergencyActive) { context.read().updateEmergency(true); + context.read().toggleLock(); HapticFeedback.heavyImpact(); } }, onLongPressStart: (_) { debugPrint('🔴 [长按开始] isEmergency=$isEmergencyActive'); + _triggerVibration(); if (isEmergencyActive && !_isPressing) { setState(() => _isPressing = true); debugPrint('🔴 [开始动画] 从 0 开始'); + _triggerVibration(); _progressController.reset(); _progressController.forward().then((_) { debugPrint('🔴 [动画完成] _isPressing=$_isPressing'); if (_isPressing && mounted) { debugPrint('✅ [解除急停] 执行'); + _triggerVibration(); context.read().updateEmergency(false); + context.read().toggleLock(); HapticFeedback.vibrate(); setState(() => _isPressing = false); } @@ -108,12 +117,15 @@ class _EmergencyStopButtonState extends State } }, onLongPressEnd: (_) { + _triggerVibration(); debugPrint('🔴 [长按结束]'); if (_isPressing) { _resetProgress(); + } }, onLongPressCancel: () { + _triggerVibration(); debugPrint('🔴 [长按取消]'); if (_isPressing) { _resetProgress(); @@ -161,4 +173,17 @@ class _EmergencyStopButtonState extends State ), ); } + + void _triggerVibration() { + Vibration.hasVibrator().then((hasVibrator) { + if (hasVibrator ?? false) { + Vibration.vibrate(duration: 50, amplitude: 380); + debugPrint(' 震动执行 - 10ms'); + } else { + debugPrint(' 设备不支持震动'); + } + }).catchError((e) { + debugPrint('震动失败:$e'); + }); + } }