2026-01-19 18:24:24 +08:00
|
|
|
|
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
2026-01-18 20:21:14 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2026-03-24 17:09:12 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2026-01-18 20:21:14 +08:00
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-04-24 15:24:43 +08:00
|
|
|
|
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
|
|
|
|
|
import '../bloc/remote_control_cubit.dart';
|
|
|
|
|
|
import 'emergency_stop_button.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class CenterControlArea extends StatelessWidget {
|
2026-01-19 18:24:24 +08:00
|
|
|
|
final double totalWidth;
|
|
|
|
|
|
|
|
|
|
|
|
const CenterControlArea({super.key, required this.totalWidth});
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final remoteState = context.watch<RemoteControlCubit>().state;
|
|
|
|
|
|
|
|
|
|
|
|
if (remoteState.isEmergency) {
|
|
|
|
|
|
return const Column(
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2026-01-19 18:24:24 +08:00
|
|
|
|
children: [EmergencyStopButton(), SizedBox(height: 16)],
|
2026-01-18 20:21:14 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-19 18:24:24 +08:00
|
|
|
|
return LayoutBuilder(
|
|
|
|
|
|
builder: (context, constraints) {
|
|
|
|
|
|
final double expandedWidth = totalWidth * 0.25;
|
|
|
|
|
|
final double emergencyStopButtonWidth = constraints.maxWidth * 0.5;
|
|
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
|
// 这里不再使用 Row 包装三个 Expanded,而是直接固定宽度
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
//mainAxisSize: MainAxisSize.min, // 极其重要:防止在 spaceBetween 下挤压
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2026-01-21 13:27:55 +08:00
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
2026-01-19 18:24:24 +08:00
|
|
|
|
children: [
|
|
|
|
|
|
// 左摇杆 (3份)
|
2026-01-21 13:27:55 +08:00
|
|
|
|
// _buildSliderBox(expandedWidth, "底盘", true),
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
width: expandedWidth,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
|
children: [
|
2026-04-28 16:55:58 +08:00
|
|
|
|
_buildSliderBox(expandedWidth, 'chassis', true,context),
|
2026-01-21 13:27:55 +08:00
|
|
|
|
SizedBox(height: totalWidth * 0.01),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
2026-01-19 18:24:24 +08:00
|
|
|
|
// 急停 (2份)
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
width: emergencyStopButtonWidth,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
EmergencyStopButton(width: emergencyStopButtonWidth),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
2026-01-19 18:24:24 +08:00
|
|
|
|
SizedBox(height: totalWidth * 0.05),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
2026-04-24 15:24:43 +08:00
|
|
|
|
Text(
|
|
|
|
|
|
AppLocalizations.of(context).translate('remote_control.switch_view_hint'),
|
|
|
|
|
|
style: const TextStyle(fontSize: 8, color: Colors.grey),
|
2026-01-19 18:24:24 +08:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
|
2026-01-19 18:24:24 +08:00
|
|
|
|
// 右摇杆 (3份)
|
2026-01-21 13:27:55 +08:00
|
|
|
|
// _buildSliderBox(expandedWidth, "备用", false),
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
|
width: expandedWidth,
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
2026-04-28 16:55:58 +08:00
|
|
|
|
children: [_buildSliderBox(expandedWidth, 'mower', false,context)],
|
2026-01-21 13:27:55 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2026-01-19 18:24:24 +08:00
|
|
|
|
],
|
2026-01-18 20:21:14 +08:00
|
|
|
|
),
|
2026-01-19 18:24:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
},
|
2026-01-18 20:21:14 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 16:55:58 +08:00
|
|
|
|
Widget _buildSliderBox(double boxWidth, String deviceKey, bool isLeft,BuildContext context) {
|
|
|
|
|
|
// 🔥 使用deviceKey作为唯一标识,不依赖显示文本
|
|
|
|
|
|
final label = deviceKey == 'chassis'
|
|
|
|
|
|
? AppLocalizations.of(context).translate('remote_control.chassis')
|
|
|
|
|
|
: AppLocalizations.of(context).translate('remote_control.mower');
|
|
|
|
|
|
|
2026-01-19 18:24:24 +08:00
|
|
|
|
return SizedBox(
|
|
|
|
|
|
width: boxWidth,
|
|
|
|
|
|
child: Center(
|
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
|
width: boxWidth * 0.6,
|
|
|
|
|
|
height: boxWidth * 0.6 * 3,
|
|
|
|
|
|
child: CCExpandSlider(
|
|
|
|
|
|
label: label,
|
|
|
|
|
|
svgStart: "assets/svgs/remote_up.svg",
|
2026-04-28 16:55:58 +08:00
|
|
|
|
svgCenter: deviceKey == 'mower'
|
|
|
|
|
|
? "assets/svgs/remote_scissors.svg"
|
|
|
|
|
|
: "assets/svgs/remote_layers.svg",
|
2026-01-19 18:24:24 +08:00
|
|
|
|
svgEnd: "assets/svgs/remote_down.svg",
|
2026-04-28 16:55:58 +08:00
|
|
|
|
onStart: () => _handleSliderAction(deviceKey, "start", context),
|
|
|
|
|
|
onCenter: () => _handleSliderAction(deviceKey, "center", context),
|
|
|
|
|
|
onEnd: () => _handleSliderAction(deviceKey, "end", context),
|
2026-01-19 18:24:24 +08:00
|
|
|
|
iconSize: boxWidth * 0.6 * 0.35,
|
|
|
|
|
|
),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
),
|
2026-01-19 18:24:24 +08:00
|
|
|
|
),
|
2026-01-18 20:21:14 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-03-17 16:10:40 +08:00
|
|
|
|
|
|
|
|
|
|
// 🔥 新增:统一的业务逻辑分发方法
|
2026-04-28 16:55:58 +08:00
|
|
|
|
void _handleSliderAction(String deviceKey, String action, BuildContext context) {
|
|
|
|
|
|
debugPrint('🎯 [Slider 业务] deviceKey: $deviceKey, action: $action');
|
|
|
|
|
|
|
|
|
|
|
|
// 🔥 使用deviceKey进行判断,不依赖显示文本
|
|
|
|
|
|
switch (deviceKey) {
|
|
|
|
|
|
case 'chassis':
|
2026-03-17 16:10:40 +08:00
|
|
|
|
_handleChassisAction(action, context);
|
|
|
|
|
|
break;
|
2026-04-28 16:55:58 +08:00
|
|
|
|
case 'mower':
|
2026-03-17 16:10:40 +08:00
|
|
|
|
_handleMowerAction(action, context);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2026-04-28 16:55:58 +08:00
|
|
|
|
debugPrint('⚠️ 未知的 deviceKey: $deviceKey');
|
2026-03-17 16:10:40 +08:00
|
|
|
|
}
|
2026-03-24 17:09:12 +08:00
|
|
|
|
// 🔥 在指令执行后触发震动反馈(增强手感)
|
|
|
|
|
|
HapticFeedback.mediumImpact();
|
2026-03-17 16:10:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 🔥 底盘的业务逻辑(左滑块)
|
|
|
|
|
|
void _handleChassisAction(String action, BuildContext context) {
|
|
|
|
|
|
final cubit = context.read<RemoteControlCubit>();
|
|
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
case "start":
|
|
|
|
|
|
debugPrint('⬆️ 底盘 - 向上(例如:前进)');
|
|
|
|
|
|
// TODO: 发送底盘前进指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendChassisCommand(1);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "center":
|
|
|
|
|
|
debugPrint('️ 底盘 - 中间(例如:停止)');
|
|
|
|
|
|
// TODO: 发送底盘停止指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendChassisCommand(0);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "end":
|
|
|
|
|
|
debugPrint('⬇️ 底盘 - 向下(例如:后退)');
|
|
|
|
|
|
// TODO: 发送底盘后退指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendChassisCommand(2);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 🔥 割刀的业务逻辑(右滑块)
|
|
|
|
|
|
void _handleMowerAction(String action, BuildContext context) {
|
|
|
|
|
|
final cubit = context.read<RemoteControlCubit>();
|
|
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
case "start":
|
|
|
|
|
|
debugPrint('⬆️ 割刀 - 向上(例如:抬刀)');
|
|
|
|
|
|
// TODO: 发送抬刀指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendMowerCommand(1);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "center":
|
|
|
|
|
|
debugPrint('⏹️ 割刀 - 中间(例如:保持)');
|
|
|
|
|
|
// TODO: 发送保持指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendMowerCommand(0);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "end":
|
|
|
|
|
|
debugPrint('⬇️ 割刀 - 向下(例如:降刀)');
|
|
|
|
|
|
// TODO: 发送降刀指令
|
2026-03-18 09:53:04 +08:00
|
|
|
|
cubit.sendMowerCommand(2);
|
2026-03-17 16:10:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-18 20:21:14 +08:00
|
|
|
|
}
|