删除撤回

This commit is contained in:
mmc
2026-02-26 09:17:14 +08:00
parent 0b936f50aa
commit 919156789b
3 changed files with 78 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
class RouteDirectionPanel extends StatefulWidget { // 重命名为Panel更符合组件语义
class RouteDirectionPanel extends StatefulWidget {
// 重命名为Panel更符合组件语义
// 接收外部传入的初始值
final bool initialOptimalHeading;
final double initialDirection;
@@ -11,7 +12,7 @@ class RouteDirectionPanel extends StatefulWidget { // 重命名为Panel更符合
const RouteDirectionPanel({
super.key,
this.initialOptimalHeading = true, // 默认开启最优航向
this.initialDirection = 0.0, // 默认方向0度
this.initialDirection = 0.0, // 默认方向0度
this.onConfirm,
this.onCancel,
});
@@ -73,8 +74,8 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
],
),
const SizedBox(height: 20),
const Divider(height: 1, color: Colors.grey),
const SizedBox(height: 20),
//const Divider(height: 1, color: Colors.grey),
//const SizedBox(height: 20),
// 最优航向开关
Row(

View File

@@ -33,9 +33,13 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
WorkMode? _currentWorkMode = WorkMode.bow; // 当前作业模式
// ========== 核心新增状态 ==========
List<LatLng> _markedPoints = []; // 存储所有打点坐标
final List<LatLng> _markedPoints = []; // 存储所有打点坐标
LatLng get _mapCenter => _mapController.center; // 实时获取地图中心坐标
double _headingAngle = 0.0; // 航向角(单位:度)
final double _headingAngle = 0.0; // 当前机器航向角(单位:度)
//打点
double _workDistance = 0.0; // 作业行距(单位:米)
double _angle = 0.0; // 航线方向角(单位:度)
// =================================
@override
@@ -50,6 +54,40 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
});
}
void _undoLastPoint() {
if (_markedPoints.isNotEmpty) {
setState(() {
_markedPoints.removeLast(); // 删除最后一个打点
});
debugPrint('撤回成功,剩余打点数量:${_markedPoints.length}');
} else {
debugPrint('无打点可撤回');
// 可选:提示用户
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('暂无打点可撤回')));
}
}
// ========== 核心:清空所有打点和轨迹 ==========
void _deleteAllPoints() {
if (_markedPoints.isNotEmpty) {
setState(() {
_markedPoints.clear(); // 清空所有打点
});
debugPrint('删除成功,已清空所有打点和轨迹');
// 可选:提示用户
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('已清空所有打点和轨迹')));
} else {
debugPrint('无打点可删除');
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('暂无打点可删除')));
}
}
/// ===============================
/// 企业级定位初始化(已修复坐标系)
/// ===============================
@@ -288,6 +326,8 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
onComplete: () {
setState(() => _isPanelOpen = false);
},
onUndoTap: _undoLastPoint,
onDeleteTap: _deleteAllPoints,
onRobotModeChanged: (mode) {
setState(() => _currentRobotMode = mode);
debugPrint('外部收到机器人模式:$mode');
@@ -301,6 +341,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
_addMarkedPoint(); // 点击加号打点
debugPrint('外部处理加号按钮点击,已添加打点');
},
onDistanceTap: (distance) {
_workDistance = distance; // 更新距离状态
debugPrint(
'外部处理作业行距距离设置,当前距离:${distance.toStringAsFixed(1)}米',
);
},
onSettingTap: () {
setState(() {
_directionBoxOpen = true;
@@ -329,6 +375,10 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
debugPrint(
'最优航向:${result['optimalHeading']},角度:${result['direction']}',
);
_angle = result['optimalHeading'] == true
? -1
: result['direction']; // 更新航线方向角状态
debugPrint('外部处理航线方向设置,当前角度:${_angle}');
setState(() => _directionBoxOpen = false);
},
onCancel: () {

View File

@@ -16,7 +16,13 @@ class BottomOperationPanel extends StatefulWidget {
final VoidCallback? onAddTap; // 加号按钮点击回调
final VoidCallback? onLandTap; // 地块标签点击回调
final VoidCallback? onRouteTap; // 航线标签点击回调
final VoidCallback? onSettingTap; // 设置标签点击回调
final VoidCallback? onSettingTap;
final ValueChanged<double>? onDistanceTap;
final VoidCallback? onDeleteTap;
final VoidCallback? onUndoTap; // 设置标签点击回调
const BottomOperationPanel({
super.key,
@@ -30,6 +36,9 @@ class BottomOperationPanel extends StatefulWidget {
this.onLandTap,
this.onRouteTap,
this.onSettingTap,
this.onDistanceTap,
this.onDeleteTap,
this.onUndoTap,
});
@override
@@ -172,6 +181,7 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
GestureDetector(
onTap: () {
debugPrint('点击了添加按钮');
widget.onAddTap?.call();
},
child: Container(
@@ -205,8 +215,14 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildActionButton(Icons.delete_outline, '删除', true, () {}),
_buildActionButton(Icons.undo_outlined, '撤回', true, () {}),
_buildActionButton(Icons.delete_outline, '删除', true, () {
debugPrint('点击了删除按钮,清空所有打点');
widget.onDeleteTap?.call();
}),
_buildActionButton(Icons.undo_outlined, '撤回', true, () {
debugPrint('点击了撤回按钮,删除最后一个打点');
widget.onUndoTap?.call();
}),
_buildActionButton(Icons.check_outlined, '完成', true, () {
widget.onComplete.call();
}),
@@ -244,6 +260,7 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
_operationDistance -= 0.1;
}
});
widget.onDistanceTap?.call(_operationDistance);
},
child: Container(
width: 30,
@@ -272,6 +289,7 @@ class _BottomOperationPanelState extends State<BottomOperationPanel> {
setState(() {
_operationDistance += 0.1;
});
widget.onDistanceTap?.call(_operationDistance);
},
child: Container(
width: 30,