远程遥控重构

This commit is contained in:
2026-04-16 10:48:50 +08:00
parent 2aadaa0205
commit c45f8ee867
3 changed files with 89 additions and 65 deletions

View File

@@ -14,6 +14,7 @@ class CCJoystick extends StatefulWidget {
final AxisHint axisHint;
final Function(JoystickValue) onValueChanged;
final VoidCallback? onPress;
final VoidCallback? onPanEnd; // 🔥 新增:松手回调
final double radius;
const CCJoystick({
@@ -21,6 +22,7 @@ class CCJoystick extends StatefulWidget {
required this.axisHint,
required this.onValueChanged,
this.onPress,
this.onPanEnd, // 🔥 新增
this.radius = 80,
});
@@ -70,6 +72,7 @@ class _CustomJoystickState extends State<CCJoystick>
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque, // 🔥 改为 opaque,确保所有触摸事件都被捕获
onPanStart: (_) => widget.onPress?.call(),
onPanUpdate: (details) {
setState(() {
@@ -91,6 +94,7 @@ class _CustomJoystickState extends State<CCJoystick>
onPanEnd: (_) {
setState(() => _offset = Offset.zero); // 归位
_updateValue();
widget.onPanEnd?.call(); // 🔥 调用松手回调
},
child: AnimatedBuilder(
animation: _floatController,