完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'remote_control_link_feedback.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
|
||||
import '../bloc/remote_control_cubit.dart';
|
||||
import '../bloc/remote_control_state.dart';
|
||||
import 'emergency_stop_button.dart';
|
||||
|
||||
class CenterControlArea extends StatelessWidget {
|
||||
@@ -43,7 +45,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_buildSliderBox(expandedWidth, 'chassis', true,context),
|
||||
_buildSliderBox(expandedWidth, 'chassis', true, context),
|
||||
SizedBox(height: totalWidth * 0.01),
|
||||
],
|
||||
),
|
||||
@@ -60,7 +62,9 @@ class CenterControlArea extends StatelessWidget {
|
||||
SizedBox(height: totalWidth * 0.05),
|
||||
|
||||
Text(
|
||||
AppLocalizations.of(context).translate('remote_control.switch_view_hint'),
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.switch_view_hint'),
|
||||
style: const TextStyle(fontSize: 8, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
@@ -73,7 +77,31 @@ class CenterControlArea extends StatelessWidget {
|
||||
width: expandedWidth,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [_buildSliderBox(expandedWidth, 'mower', false,context)],
|
||||
children: [
|
||||
_buildSliderBox(expandedWidth, 'mower', false, context),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).translate('remote_control.mower_last_operation', {
|
||||
'operation': AppLocalizations.of(context).translate(
|
||||
switch (remoteState.lastMowerOperation) {
|
||||
MowerLastOperation.turnOn =>
|
||||
'remote_control.mower_operation_on',
|
||||
MowerLastOperation.turnOff =>
|
||||
'remote_control.mower_operation_off',
|
||||
MowerLastOperation.none =>
|
||||
'remote_control.mower_operation_none',
|
||||
},
|
||||
),
|
||||
}),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.65),
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -83,12 +111,17 @@ class CenterControlArea extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSliderBox(double boxWidth, String deviceKey, bool isLeft,BuildContext context) {
|
||||
Widget _buildSliderBox(
|
||||
double boxWidth,
|
||||
String deviceKey,
|
||||
bool isLeft,
|
||||
BuildContext context,
|
||||
) {
|
||||
// 🔥 使用deviceKey作为唯一标识,不依赖显示文本
|
||||
final label = deviceKey == 'chassis'
|
||||
final label = deviceKey == 'chassis'
|
||||
? AppLocalizations.of(context).translate('remote_control.chassis')
|
||||
: AppLocalizations.of(context).translate('remote_control.mower');
|
||||
|
||||
|
||||
return SizedBox(
|
||||
width: boxWidth,
|
||||
child: Center(
|
||||
@@ -98,7 +131,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
child: CCExpandSlider(
|
||||
label: label,
|
||||
svgStart: "assets/svgs/remote_up.svg",
|
||||
svgCenter: deviceKey == 'mower'
|
||||
svgCenter: deviceKey == 'mower'
|
||||
? "assets/svgs/remote_scissors.svg"
|
||||
: "assets/svgs/remote_layers.svg",
|
||||
svgEnd: "assets/svgs/remote_down.svg",
|
||||
@@ -113,7 +146,12 @@ class CenterControlArea extends StatelessWidget {
|
||||
}
|
||||
|
||||
// 🔥 新增:统一的业务逻辑分发方法
|
||||
void _handleSliderAction(String deviceKey, String action, BuildContext context) {
|
||||
void _handleSliderAction(
|
||||
String deviceKey,
|
||||
String action,
|
||||
BuildContext context,
|
||||
) {
|
||||
RemoteControlLinkNotice.showIfDisconnected(context);
|
||||
debugPrint('🎯 [Slider 业务] deviceKey: $deviceKey, action: $action');
|
||||
|
||||
// 🔥 门槛检查:与摇杆一致,未收到 TCP 0x02 推送时禁止操作并提示。
|
||||
@@ -133,7 +171,7 @@ class CenterControlArea extends StatelessWidget {
|
||||
_handleMowerAction(action, context);
|
||||
break;
|
||||
default:
|
||||
debugPrint('⚠️ 未知的 deviceKey: $deviceKey');
|
||||
debugPrint('⚠️ 未知的 deviceKey: $deviceKey');
|
||||
}
|
||||
// 🔥 在指令执行后触发震动反馈(增强手感)
|
||||
HapticFeedback.mediumImpact();
|
||||
@@ -147,40 +185,34 @@ class CenterControlArea extends StatelessWidget {
|
||||
case "start":
|
||||
debugPrint('⬆️ 底盘 - 向上(例如:前进)');
|
||||
// TODO: 发送底盘前进指令
|
||||
cubit.sendChassisCommand(1);
|
||||
cubit.sendChassisCommand(1);
|
||||
break;
|
||||
case "center":
|
||||
debugPrint('️ 底盘 - 中间(例如:停止)');
|
||||
// TODO: 发送底盘停止指令
|
||||
cubit.sendChassisCommand(0);
|
||||
cubit.sendChassisCommand(0);
|
||||
break;
|
||||
case "end":
|
||||
debugPrint('⬇️ 底盘 - 向下(例如:后退)');
|
||||
// TODO: 发送底盘后退指令
|
||||
cubit.sendChassisCommand(2);
|
||||
cubit.sendChassisCommand(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 🔥 割刀的业务逻辑(右滑块)
|
||||
// 割刀开关(右滑块);段位映射由 Cubit 统一处理。
|
||||
void _handleMowerAction(String action, BuildContext context) {
|
||||
final cubit = context.read<RemoteControlCubit>();
|
||||
|
||||
switch (action) {
|
||||
case "start":
|
||||
debugPrint('⬆️ 割刀 - 向上(例如:抬刀)');
|
||||
// TODO: 发送抬刀指令
|
||||
cubit.sendMowerCommand(1);
|
||||
cubit.sendMowerSliderCommand(1);
|
||||
break;
|
||||
case "center":
|
||||
debugPrint('⏹️ 割刀 - 中间(例如:保持)');
|
||||
// TODO: 发送保持指令
|
||||
cubit.sendMowerCommand(0);
|
||||
cubit.sendMowerSliderCommand(0);
|
||||
break;
|
||||
case "end":
|
||||
debugPrint('⬇️ 割刀 - 向下(例如:降刀)');
|
||||
// TODO: 发送降刀指令
|
||||
cubit.sendMowerCommand(2);
|
||||
cubit.sendMowerSliderCommand(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user