This commit is contained in:
mmc
2026-02-25 20:00:33 +08:00
parent 27717cbba2
commit 07a653fca5
4 changed files with 567 additions and 223 deletions

View File

@@ -7,6 +7,8 @@ class BottomOperationPanel extends StatefulWidget {
// 外部传入的初始值
final RobotMode initialRobotMode;
final AreaMode initialAreaMode;
// 新增:外部控制初始选中的标签(默认地块)
final String initialSelectedTab;
// 回调函数:向外部传递事件
final VoidCallback onComplete; // 完成按钮点击回调
final ValueChanged<RobotMode>? onRobotModeChanged; // 机器人模式变更回调
@@ -14,17 +16,20 @@ class BottomOperationPanel extends StatefulWidget {
final VoidCallback? onAddTap; // 加号按钮点击回调
final VoidCallback? onLandTap; // 地块标签点击回调
final VoidCallback? onRouteTap; // 航线标签点击回调
final VoidCallback? onSettingTap; // 设置标签点击回调
const BottomOperationPanel({
super.key,
this.initialRobotMode = RobotMode.point,
this.initialAreaMode = AreaMode.work,
this.initialSelectedTab = '地块', // 默认选中地块
required this.onComplete, // 完成按钮必须传
this.onRobotModeChanged,
this.onAreaModeChanged,
this.onAddTap,
this.onLandTap,
this.onRouteTap,
this.onSettingTap,
});
@override
@@ -34,6 +39,10 @@ class BottomOperationPanel extends StatefulWidget {
class _BottomOperationPanelState extends State<BottomOperationPanel> {
late RobotMode _robotMode;
late AreaMode _areaMode;
// 新增:当前选中的标签(地块/航线)- 核心状态
late String _currentTab;
// 新增:航线模式下的作业行距(默认0.5米)
double _operationDistance = 0.5;
@override
void initState() {
@@ -41,6 +50,8 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
// 初始化外部传入的默认值
_robotMode = widget.initialRobotMode;
_areaMode = widget.initialAreaMode;
// 初始化选中的标签
_currentTab = widget.initialSelectedTab;
}
@override
@@ -52,87 +63,13 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8)],
),
padding: const EdgeInsets.all(16),
constraints: const BoxConstraints(minHeight: 260),
//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),
// 底部标签页切换
_buildTabContent(),
// 底部标签页切换(修复背景色切换+状态更新)
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
@@ -143,13 +80,19 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_currentTab = '地块'; // 更新选中状态
});
debugPrint('切换到地块标签');
widget.onLandTap?.call();
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
// 选中地块时背景为白色,否则透明
decoration: BoxDecoration(
color: Colors.white,
color: _currentTab == '地块'
? Colors.white
: Colors.transparent,
borderRadius: BorderRadius.circular(8),
),
child: const Center(
@@ -167,13 +110,29 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_currentTab = '航线'; // 更新选中状态
});
debugPrint('切换到航线标签');
widget.onRouteTap?.call();
},
child: const Center(
child: Text(
'航线',
style: TextStyle(color: Colors.grey, fontSize: 16),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10),
// 选中航线时背景为白色,否则透明
decoration: BoxDecoration(
color: _currentTab == '航线'
? Colors.white
: Colors.transparent,
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Text(
'航线',
style: TextStyle(
color: Colors.black87,
fontSize: 16,
),
),
),
),
),
@@ -188,6 +147,182 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
);
}
// 地块模式内容构建方法
Widget _buildLandContent() {
return 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),
],
);
}
// 标签内容切换方法(地块/航线)
Widget _buildTabContent() {
if (_currentTab == '地块') {
// 地块模式:显示机器人/区域选择+操作按钮
return _buildLandContent();
} else {
// 航线模式:显示作业行距+航线方向设置
return Column(
children: [
// 作业行距配置行
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'作业行距(米)',
style: TextStyle(fontSize: 16, color: Colors.black87),
),
Row(
children: [
// 减号按钮
GestureDetector(
onTap: () {
setState(() {
if (_operationDistance > 0.1) {
_operationDistance -= 0.1;
}
});
},
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: Colors.grey[200],
shape: BoxShape.circle,
),
child: const Icon(
Icons.remove,
size: 16,
color: Colors.black87,
),
),
),
const SizedBox(width: 10),
// 行距数值
Text(
'${_operationDistance.toStringAsFixed(1)}',
style: const TextStyle(fontSize: 16, color: Colors.black87),
),
const SizedBox(width: 10),
// 加号按钮
GestureDetector(
onTap: () {
setState(() {
_operationDistance += 0.1;
});
},
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: Colors.grey[200],
shape: BoxShape.circle,
),
child: const Icon(
Icons.add,
size: 16,
color: Colors.black87,
),
),
),
],
),
],
),
const SizedBox(height: 16),
// 航线方向配置行
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'航线方向',
style: TextStyle(fontSize: 16, color: Colors.black87),
),
// 设置按钮
ElevatedButton(
onPressed: () {
widget.onSettingTap?.call();
debugPrint('点击了航线方向设置按钮');
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF00C853),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
),
child: const Text('设置'),
),
],
),
],
);
}
}
// 构建操作按钮
Widget _buildActionButton(
IconData icon,