94 lines
2.8 KiB
Dart
94 lines
2.8 KiB
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});
|
||
|
|
|
||
|
|
@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),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
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,
|
||
|
|
),
|
||
|
|
|
||
|
|
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 _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)),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|