From d547ed2480cfc89fc5866dff85ae44718c6a1291 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Sat, 28 Feb 2026 13:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=80=89=E4=B8=AD=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=B7=AF=E5=BE=84=20=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/widgets/common/enum.dart | 10 ++- .../widgets/map/testmap_pages.dart | 70 ++++++++++--------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/lib/features/home/presentation/widgets/common/enum.dart b/lib/features/home/presentation/widgets/common/enum.dart index b123a18b..964f2b03 100644 --- a/lib/features/home/presentation/widgets/common/enum.dart +++ b/lib/features/home/presentation/widgets/common/enum.dart @@ -1,4 +1,12 @@ -enum WorkMode { bow, custom } +enum WorkMode { + bow("0"), // 作业模式:bow,值为0 + custom("2"); // 作业模式:custom,值为2 + + // 定义枚举的数值属性 + final String value; + // 枚举构造函数(必须是const) + const WorkMode(this.value); +} enum RobotMode { point, robot } diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 36b08b3d..3d5fa492 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -43,6 +43,12 @@ class PlotData { }); } +class PlotDataPath { + final dynamic? jsonData; // 原始数据的JSON字符串(可选,便于调试或后续使用) + + PlotDataPath({this.jsonData}); +} + class MapPageEnterprise extends StatefulWidget { const MapPageEnterprise({Key? key}) : super(key: key); @@ -68,6 +74,7 @@ class _MapPageEnterpriseState extends State { bool _isListBoxOpen = false; //列表面板显示/隐藏 // 新增:存储选中的地块(null表示未选中) PlotData? _selectedPlot; + PlotDataPath? _selectedPlotPath; // 存储选中地块的路径数据(可选) // 新增:控制底部作业面板显示 bool _isWorkPanelOpen = false; @@ -482,9 +489,7 @@ class _MapPageEnterpriseState extends State { Widget _buildWorkPanel() { return BlocBuilder( builder: (context, state) { - print( - '当前DevicesState的pathData: ${state}', - ); // 调试输出,查看pathData内容 + print('当前DevicesState的pathData: ${state}'); // 调试输出,查看pathData内容 // 无选中地块或无路径数据时返回空 if (_selectedPlot == null || state.pathData == null) { return const SizedBox.shrink(); @@ -493,22 +498,34 @@ class _MapPageEnterpriseState extends State { // 解析路径数据(根据你的实际数据结构调整) List> pathRecords = []; if (state.pathData is List) { - pathRecords = state.pathData as List>; - } + // 第一步:安全转换为List,并过滤掉非Map的元素 + final List rawList = state.pathData as List; + pathRecords = rawList + .where((item) => item is Map) + .cast>() + .toList(); - // 提取关键信息用于展示 - String workArea = '0 亩'; - int pointCount = 0; - String workMode = '未知'; - if (pathRecords.isNotEmpty) { - final record = pathRecords.first; - workArea = record['workingArea']?.toString() ?? '0 亩'; - pointCount = record['plotPoints'] != null - ? (record['plotPoints'] as List).length - : 0; - workMode = record['workMode'] ?? '未知'; + // 第二步:只有列表非空时才赋值第一条数据 + if (pathRecords.isNotEmpty) { + _selectedPlotPath = PlotDataPath(jsonData: pathRecords.first); + } else { + _selectedPlotPath = null; // 空列表时清空,避免残留旧数据 + } + } else { + _selectedPlotPath = null; // 非List类型时清空 } - + print( + _selectedPlotPath == null + ? '无数据' + : 'path坐标: ${jsonDecode(_selectedPlotPath!.jsonData['jsonData'] as String)['planModel']}', + ); + String workMode = + jsonDecode( + _selectedPlotPath!.jsonData['jsonData'] as String, + )['planModel'] == + WorkMode.bow.value + ? "弓字模式" + : "自定义模式"; return Positioned( left: 0, right: 0, @@ -570,21 +587,7 @@ class _MapPageEnterpriseState extends State { overflow: TextOverflow.ellipsis, ), const SizedBox(height: 4), - // 新增:展示路径数据关键信息 - Text( - '作业面积:$workArea', - style: const TextStyle( - fontSize: 14, - color: Colors.grey, - ), - ), - Text( - '打点数量:$pointCount 个', - style: const TextStyle( - fontSize: 14, - color: Colors.grey, - ), - ), + Text( '作业模式:$workMode', style: const TextStyle( @@ -657,7 +660,7 @@ class _MapPageEnterpriseState extends State { // 3. 开始作业按钮(加载中禁用) SizedBox( width: double.infinity, - height: 48, + height: 50, child: ElevatedButton( onPressed: state.isLoading || pathRecords.isEmpty ? null @@ -963,6 +966,7 @@ class _MapPageEnterpriseState extends State { setState(() { _isListBoxOpen = isOpen; + _isWorkPanelOpen = false; }); }, onWorkModeSelected: (mode) {