远程遥控界面编写

This commit is contained in:
CC
2026-01-19 18:24:24 +08:00
parent 289e706337
commit 32b702fb6d
48 changed files with 1118 additions and 303 deletions

View File

@@ -1,93 +1,90 @@
import 'package:cc_ui_kit/cc_ui_kit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../bloc/remote_control_cubit.dart';
import 'emergency_stop_button.dart';
import 'middle_expandslider.dart';
class CenterControlArea extends StatelessWidget {
const CenterControlArea({super.key});
final double totalWidth;
const CenterControlArea({super.key, required this.totalWidth});
@override
Widget build(BuildContext context) {
final remoteState = context.watch<RemoteControlCubit>().state;
// 如果处于急停激活状态,根据 Compose 逻辑,中间只显示急停状态
if (remoteState.isEmergency) {
return const Column(
mainAxisSize: MainAxisSize.min,
children: [
EmergencyStopButton(), // 刚才写的带 3 秒解除逻辑的按钮
SizedBox(height: 16),
],
children: [EmergencyStopButton(), SizedBox(height: 16)],
);
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
// 左推杆:底盘升降 (对应 Compose 的第一个 MiddleExpandSlider)
_buildVerticalSlider(
label: "底盘",
onTop: () =>
context.read<RemoteControlCubit>().updateChassisLift(1),
onMiddle: () =>
context.read<RemoteControlCubit>().updateChassisLift(0),
onBottom: () =>
context.read<RemoteControlCubit>().updateChassisLift(2),
iconTop: Icons.expand_less,
iconMiddle: Icons.layers,
iconBottom: Icons.expand_more,
return LayoutBuilder(
builder: (context, constraints) {
final double expandedWidth = totalWidth * 0.25;
final double emergencyStopButtonWidth = constraints.maxWidth * 0.5;
return Container(
height: 180,
// 这里不再使用 Row 包装三个 Expanded,而是直接固定宽度
child: Row(
//mainAxisSize: MainAxisSize.min, // 极其重要:防止在 spaceBetween 下挤压
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// 左摇杆 (3份)
_buildSliderBox(expandedWidth, "底盘", true),
// 急停 (2份)
SizedBox(
width: emergencyStopButtonWidth,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
EmergencyStopButton(width: emergencyStopButtonWidth),
SizedBox(height: totalWidth * 0.05),
const Text(
'双击空白处切换视角',
style: TextStyle(
fontSize: 8,
color: Colors.grey,
),
),
],
),
),
// 右摇杆 (3份)
_buildSliderBox(expandedWidth, "备用", false),
],
),
);
},
);
}
const SizedBox(width: 24),
// 中间:急停按钮
const EmergencyStopButton(),
const SizedBox(width: 24),
// 右推杆:备用/其他 (对应 Compose 的第二个 MiddleExpandSlider)
_buildVerticalSlider(
label: "云台",
onTop: () {}, // 预留接口
onMiddle: () {},
onBottom: () {},
iconTop: Icons.keyboard_arrow_up,
iconMiddle: Icons.videocam,
iconBottom: Icons.keyboard_arrow_down,
Widget _buildSliderBox(double boxWidth, String label, bool isLeft) {
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",
svgCenter: "assets/svgs/remote_layers.svg",
svgEnd: "assets/svgs/remote_down.svg",
onStart: () => print("$label start"),
onCenter: () => print("$label center"),
onEnd: () => print("$label end"),
iconSize: boxWidth * 0.6 * 0.35,
),
],
),
),
);
}
// 快捷构建推杆的方法
Widget _buildVerticalSlider({
required String label,
required VoidCallback onTop,
required VoidCallback onMiddle,
required VoidCallback onBottom,
required IconData iconTop,
required IconData iconMiddle,
required IconData iconBottom,
}) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
MiddleExpandSlider(
onTop: onTop,
onMiddle: onMiddle,
onBottom: onBottom,
iconTop: iconTop,
iconMiddle: iconMiddle,
iconBottom: iconBottom,
),
const SizedBox(height: 8),
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 12)),
],
);
}
}