增加急停的振动感
This commit is contained in:
@@ -27,6 +27,13 @@ class RemoteControlPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _RemoteControlPageState extends State<RemoteControlPage> {
|
class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||||
String _videoStreamUrl = "";
|
String _videoStreamUrl = "";
|
||||||
|
late RemoteControlCubit _cubit;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
_cubit = context.read<RemoteControlCubit>();
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -48,7 +55,8 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
context.read<RemoteControlCubit>().stopControlLoop();
|
// context.read<RemoteControlCubit>().stopControlLoop();
|
||||||
|
_cubit.stopControlLoop();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
|
import 'package:vibration/vibration.dart';
|
||||||
|
|
||||||
import '../bloc/remote_control_cubit.dart';
|
import '../bloc/remote_control_cubit.dart';
|
||||||
|
|
||||||
@@ -49,6 +50,8 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
|||||||
_progressController.value = 0;
|
_progressController.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isEmergencyActive = context
|
final isEmergencyActive = context
|
||||||
@@ -85,22 +88,28 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
|||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
debugPrint('🔴 [点击] 触发急停');
|
debugPrint('🔴 [点击] 触发急停');
|
||||||
|
_triggerVibration();
|
||||||
if (!isEmergencyActive) {
|
if (!isEmergencyActive) {
|
||||||
context.read<RemoteControlCubit>().updateEmergency(true);
|
context.read<RemoteControlCubit>().updateEmergency(true);
|
||||||
|
context.read<RemoteControlCubit>().toggleLock();
|
||||||
HapticFeedback.heavyImpact();
|
HapticFeedback.heavyImpact();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPressStart: (_) {
|
onLongPressStart: (_) {
|
||||||
debugPrint('🔴 [长按开始] isEmergency=$isEmergencyActive');
|
debugPrint('🔴 [长按开始] isEmergency=$isEmergencyActive');
|
||||||
|
_triggerVibration();
|
||||||
if (isEmergencyActive && !_isPressing) {
|
if (isEmergencyActive && !_isPressing) {
|
||||||
setState(() => _isPressing = true);
|
setState(() => _isPressing = true);
|
||||||
debugPrint('🔴 [开始动画] 从 0 开始');
|
debugPrint('🔴 [开始动画] 从 0 开始');
|
||||||
|
_triggerVibration();
|
||||||
_progressController.reset();
|
_progressController.reset();
|
||||||
_progressController.forward().then((_) {
|
_progressController.forward().then((_) {
|
||||||
debugPrint('🔴 [动画完成] _isPressing=$_isPressing');
|
debugPrint('🔴 [动画完成] _isPressing=$_isPressing');
|
||||||
if (_isPressing && mounted) {
|
if (_isPressing && mounted) {
|
||||||
debugPrint('✅ [解除急停] 执行');
|
debugPrint('✅ [解除急停] 执行');
|
||||||
|
_triggerVibration();
|
||||||
context.read<RemoteControlCubit>().updateEmergency(false);
|
context.read<RemoteControlCubit>().updateEmergency(false);
|
||||||
|
context.read<RemoteControlCubit>().toggleLock();
|
||||||
HapticFeedback.vibrate();
|
HapticFeedback.vibrate();
|
||||||
setState(() => _isPressing = false);
|
setState(() => _isPressing = false);
|
||||||
}
|
}
|
||||||
@@ -108,12 +117,15 @@ class _EmergencyStopButtonState extends State<EmergencyStopButton>
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPressEnd: (_) {
|
onLongPressEnd: (_) {
|
||||||
|
_triggerVibration();
|
||||||
debugPrint('🔴 [长按结束]');
|
debugPrint('🔴 [长按结束]');
|
||||||
if (_isPressing) {
|
if (_isPressing) {
|
||||||
_resetProgress();
|
_resetProgress();
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPressCancel: () {
|
onLongPressCancel: () {
|
||||||
|
_triggerVibration();
|
||||||
debugPrint('🔴 [长按取消]');
|
debugPrint('🔴 [长按取消]');
|
||||||
if (_isPressing) {
|
if (_isPressing) {
|
||||||
_resetProgress();
|
_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