From 919156789bc4e51cd3be59a5d4011e9bce7c3eaa Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Thu, 26 Feb 2026 09:17:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=92=A4=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widgets/BottomDirectionLine.dart | 9 ++-- .../widgets/map/testmap_pages.dart | 54 ++++++++++++++++++- .../presentation/widgets/startpoint_area.dart | 24 +++++++-- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/lib/features/home/presentation/widgets/BottomDirectionLine.dart b/lib/features/home/presentation/widgets/BottomDirectionLine.dart index 188a5d29..85c6ee82 100644 --- a/lib/features/home/presentation/widgets/BottomDirectionLine.dart +++ b/lib/features/home/presentation/widgets/BottomDirectionLine.dart @@ -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 { ], ), 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( diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 2d2df9ea..e71c5a3a 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -33,9 +33,13 @@ class _MapPageEnterpriseState extends State { WorkMode? _currentWorkMode = WorkMode.bow; // 当前作业模式 // ========== 核心新增状态 ========== - List _markedPoints = []; // 存储所有打点坐标 + final List _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 { }); } + 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 { onComplete: () { setState(() => _isPanelOpen = false); }, + onUndoTap: _undoLastPoint, + onDeleteTap: _deleteAllPoints, onRobotModeChanged: (mode) { setState(() => _currentRobotMode = mode); debugPrint('外部收到机器人模式:$mode'); @@ -301,6 +341,12 @@ class _MapPageEnterpriseState extends State { _addMarkedPoint(); // 点击加号打点 debugPrint('外部处理加号按钮点击,已添加打点'); }, + onDistanceTap: (distance) { + _workDistance = distance; // 更新距离状态 + debugPrint( + '外部处理作业行距距离设置,当前距离:${distance.toStringAsFixed(1)}米', + ); + }, onSettingTap: () { setState(() { _directionBoxOpen = true; @@ -329,6 +375,10 @@ class _MapPageEnterpriseState extends State { debugPrint( '最优航向:${result['optimalHeading']},角度:${result['direction']}', ); + _angle = result['optimalHeading'] == true + ? -1 + : result['direction']; // 更新航线方向角状态 + debugPrint('外部处理航线方向设置,当前角度:${_angle}'); setState(() => _directionBoxOpen = false); }, onCancel: () { diff --git a/lib/features/home/presentation/widgets/startpoint_area.dart b/lib/features/home/presentation/widgets/startpoint_area.dart index 5605fd37..3737971f 100644 --- a/lib/features/home/presentation/widgets/startpoint_area.dart +++ b/lib/features/home/presentation/widgets/startpoint_area.dart @@ -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? 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 { GestureDetector( onTap: () { debugPrint('点击了添加按钮'); + widget.onAddTap?.call(); }, child: Container( @@ -205,8 +215,14 @@ class _BottomOperationPanelState extends State { 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 { _operationDistance -= 0.1; } }); + widget.onDistanceTap?.call(_operationDistance); }, child: Container( width: 30, @@ -272,6 +289,7 @@ class _BottomOperationPanelState extends State { setState(() { _operationDistance += 0.1; }); + widget.onDistanceTap?.call(_operationDistance); }, child: Container( width: 30,