增加急停的振动感
This commit is contained in:
@@ -27,6 +27,13 @@ class RemoteControlPage extends StatefulWidget {
|
||||
|
||||
class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
String _videoStreamUrl = "";
|
||||
late RemoteControlCubit _cubit;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_cubit = context.read<RemoteControlCubit>();
|
||||
}
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -48,7 +55,8 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||
void dispose() {
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
context.read<RemoteControlCubit>().stopControlLoop();
|
||||
// context.read<RemoteControlCubit>().stopControlLoop();
|
||||
_cubit.stopControlLoop();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<EmergencyStopButton>
|
||||
_progressController.value = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isEmergencyActive = context
|
||||
@@ -85,22 +88,28 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
debugPrint('🔴 [点击] 触发急停');
|
||||
_triggerVibration();
|
||||
if (!isEmergencyActive) {
|
||||
context.read<RemoteControlCubit>().updateEmergency(true);
|
||||
context.read<RemoteControlCubit>().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<RemoteControlCubit>().updateEmergency(false);
|
||||
context.read<RemoteControlCubit>().toggleLock();
|
||||
HapticFeedback.vibrate();
|
||||
setState(() => _isPressing = false);
|
||||
}
|
||||
@@ -108,12 +117,15 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
||||
}
|
||||
},
|
||||
onLongPressEnd: (_) {
|
||||
_triggerVibration();
|
||||
debugPrint('🔴 [长按结束]');
|
||||
if (_isPressing) {
|
||||
_resetProgress();
|
||||
|
||||
}
|
||||
},
|
||||
onLongPressCancel: () {
|
||||
_triggerVibration();
|
||||
debugPrint('🔴 [长按取消]');
|
||||
if (_isPressing) {
|
||||
_resetProgress();
|
||||
@@ -161,4 +173,17 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _triggerVibration() {
|
||||
Vibration.hasVibrator().then((hasVibrator) {
|
||||
if (hasVibrator ?? false) {
|
||||
Vibration.vibrate(duration: 50, amplitude: 380);
|
||||
debugPrint(' 震动执行 - 10ms');
|
||||
} else {
|
||||
debugPrint(' 设备不支持震动');
|
||||
}
|
||||
}).catchError((e) {
|
||||
debugPrint('震动失败:$e');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user