221 lines
7.5 KiB
Dart
221 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:maibu_satabot_v2/features/home/presentation/widgets/common/enum.dart';
|
|
import 'package:maibu_satabot_v2/features/home/presentation/widgets/map/testmap_pages.dart';
|
|
|
|
/// 底部操作面板独立组件
|
|
class BottomOperationPanel extends StatefulWidget {
|
|
// 外部传入的初始值
|
|
final RobotMode initialRobotMode;
|
|
final AreaMode initialAreaMode;
|
|
// 回调函数:向外部传递事件
|
|
final VoidCallback onComplete; // 完成按钮点击回调
|
|
final ValueChanged<RobotMode>? onRobotModeChanged; // 机器人模式变更回调
|
|
final ValueChanged<AreaMode>? onAreaModeChanged; // 作业区域模式变更回调
|
|
final VoidCallback? onAddTap; // 加号按钮点击回调
|
|
final VoidCallback? onLandTap; // 地块标签点击回调
|
|
final VoidCallback? onRouteTap; // 航线标签点击回调
|
|
|
|
const BottomOperationPanel({
|
|
super.key,
|
|
this.initialRobotMode = RobotMode.point,
|
|
this.initialAreaMode = AreaMode.work,
|
|
required this.onComplete, // 完成按钮必须传
|
|
this.onRobotModeChanged,
|
|
this.onAreaModeChanged,
|
|
this.onAddTap,
|
|
this.onLandTap,
|
|
this.onRouteTap,
|
|
});
|
|
|
|
@override
|
|
State<BottomOperationPanel> createState() => _BottomOperationPanelState();
|
|
}
|
|
|
|
class _BottomOperationPanelState extends State<BottomOperationPanel> {
|
|
late RobotMode _robotMode;
|
|
late AreaMode _areaMode;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// 初始化外部传入的默认值
|
|
_robotMode = widget.initialRobotMode;
|
|
_areaMode = widget.initialAreaMode;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8)],
|
|
),
|
|
padding: const EdgeInsets.all(16),
|
|
constraints: const BoxConstraints(minHeight: 260),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// 面板核心内容
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
DropdownButton<RobotMode>(
|
|
value: _robotMode,
|
|
items: const [
|
|
DropdownMenuItem(
|
|
value: RobotMode.point,
|
|
child: Text("地图打点"),
|
|
),
|
|
DropdownMenuItem(
|
|
value: RobotMode.robot,
|
|
child: Text("机器人模式"),
|
|
),
|
|
],
|
|
onChanged: (v) {
|
|
if (v != null) {
|
|
setState(() => _robotMode = v);
|
|
// 触发回调,把选中的模式传给外部
|
|
widget.onRobotModeChanged?.call(v);
|
|
}
|
|
},
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
debugPrint('点击了添加按钮');
|
|
// 触发加号按钮回调
|
|
widget.onAddTap?.call();
|
|
},
|
|
child: Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFF00C853),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(Icons.add, color: Colors.white, size: 32),
|
|
),
|
|
),
|
|
DropdownButton<AreaMode>(
|
|
value: _areaMode,
|
|
items: const [
|
|
DropdownMenuItem(value: AreaMode.work, child: Text("作业区域")),
|
|
DropdownMenuItem(
|
|
value: AreaMode.obstacle,
|
|
child: Text("障碍区域"),
|
|
),
|
|
],
|
|
onChanged: (v) {
|
|
if (v != null) {
|
|
setState(() => _areaMode = v);
|
|
// 触发回调,把选中的区域模式传给外部
|
|
widget.onAreaModeChanged?.call(v);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 32),
|
|
|
|
// 操作按钮行
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildActionButton(Icons.delete_outline, '删除', true, () {}),
|
|
_buildActionButton(Icons.undo_outlined, '撤回', true, () {}),
|
|
_buildActionButton(Icons.check_outlined, '完成', true, () {
|
|
// 触发完成按钮回调,通知外部关闭面板
|
|
widget.onComplete.call();
|
|
}),
|
|
],
|
|
),
|
|
const SizedBox(height: 32),
|
|
|
|
// 底部标签页切换
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[200],
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
debugPrint('切换到地块标签');
|
|
widget.onLandTap?.call();
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Center(
|
|
child: Text(
|
|
'地块',
|
|
style: TextStyle(
|
|
color: Colors.black87,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
debugPrint('切换到航线标签');
|
|
widget.onRouteTap?.call();
|
|
},
|
|
child: const Center(
|
|
child: Text(
|
|
'航线',
|
|
style: TextStyle(color: Colors.grey, fontSize: 16),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 构建操作按钮
|
|
Widget _buildActionButton(
|
|
IconData icon,
|
|
String label,
|
|
bool isEnabled,
|
|
VoidCallback onTap,
|
|
) {
|
|
return GestureDetector(
|
|
onTap: isEnabled ? onTap : null,
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: 50,
|
|
height: 50,
|
|
decoration: BoxDecoration(
|
|
color: isEnabled ? Colors.blue : Colors.grey[300],
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(icon, color: Colors.white),
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
label,
|
|
style: TextStyle(color: isEnabled ? Colors.black : Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|