优化和路径规划新适配
This commit is contained in:
@@ -23,6 +23,49 @@ class RightJoystickArea extends StatefulWidget {
|
||||
|
||||
class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
int _lastX = 0;
|
||||
bool _hasShownNoPushDialog = false; // 防止重复弹窗
|
||||
|
||||
/// 检查是否可以控制,不能则弹出提示
|
||||
bool _checkCanControl(BuildContext context) {
|
||||
final cubit = context.read<RemoteControlCubit>();
|
||||
if (!cubit.isStatusPushActive()) {
|
||||
if (!_hasShownNoPushDialog) {
|
||||
_hasShownNoPushDialog = true;
|
||||
_showNoStatusPushDialog(context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_hasShownNoPushDialog = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// 显示暂未收到推送的提示弹窗(小圆角)
|
||||
void _showNoStatusPushDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xE5333333),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Text(
|
||||
'暂未收到该机器的推送,不能控制',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
// 1.5秒后自动关闭
|
||||
Future.delayed(const Duration(milliseconds: 1500), () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -38,6 +81,7 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
radius: widget.width,
|
||||
axisHint: AxisHint.leftRight,
|
||||
onValueChanged: (value) {
|
||||
if (!_checkCanControl(context)) return;
|
||||
int currentX = value.x.toInt();
|
||||
if (currentX == _lastX) return;
|
||||
_lastX = currentX;
|
||||
@@ -46,8 +90,12 @@ class _RightJoystickAreaState extends State<RightJoystickArea> {
|
||||
debugPrint('右摇杆的数据- x: $finalX, y: 0');
|
||||
context.read<RemoteControlCubit>().updateOriginX(finalX);
|
||||
},
|
||||
onPress: _triggerVibration,
|
||||
onPress: () {
|
||||
if (!_checkCanControl(context)) return;
|
||||
_triggerVibration();
|
||||
},
|
||||
onPanEnd: () async {
|
||||
_hasShownNoPushDialog = false; // 松手重置,下次触摸重新检查
|
||||
debugPrint('🕹️ [右摇杆] 松手,强制 X=0, Y=0');
|
||||
_lastX = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user