Files
flutterApp/lib/features/remote_control/presentation/widgets/center_control_area.dart

105 lines
3.3 KiB
Dart
Raw Normal View History

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';
import 'package:flutter_bloc/flutter_bloc.dart';
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: [
_buildSliderBox(expandedWidth, "底盘", true),
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-01-19 18:24:24 +08:00
const Text(
'双击空白处切换视角',
2026-01-21 13:27:55 +08:00
style: 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,
children: [_buildSliderBox(expandedWidth, "备用", false)],
),
),
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-01-19 18:24:24 +08:00
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",
2026-01-21 13:27:55 +08:00
onStart: () => debugPrint("$label start"),
onCenter: () => debugPrint("$label center"),
onEnd: () => debugPrint("$label end"),
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
);
}
}