点击选中 获取路径 的结果 完成

This commit is contained in:
mmc
2026-02-28 13:20:07 +08:00
parent a55dd457ab
commit d547ed2480
2 changed files with 46 additions and 34 deletions

View File

@@ -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 } enum RobotMode { point, robot }

View File

@@ -43,6 +43,12 @@ class PlotData {
}); });
} }
class PlotDataPath {
final dynamic? jsonData; // 原始数据的JSON字符串(可选,便于调试或后续使用)
PlotDataPath({this.jsonData});
}
class MapPageEnterprise extends StatefulWidget { class MapPageEnterprise extends StatefulWidget {
const MapPageEnterprise({Key? key}) : super(key: key); const MapPageEnterprise({Key? key}) : super(key: key);
@@ -68,6 +74,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
bool _isListBoxOpen = false; //列表面板显示/隐藏 bool _isListBoxOpen = false; //列表面板显示/隐藏
// 新增:存储选中的地块(null表示未选中) // 新增:存储选中的地块(null表示未选中)
PlotData? _selectedPlot; PlotData? _selectedPlot;
PlotDataPath? _selectedPlotPath; // 存储选中地块的路径数据(可选)
// 新增:控制底部作业面板显示 // 新增:控制底部作业面板显示
bool _isWorkPanelOpen = false; bool _isWorkPanelOpen = false;
@@ -482,9 +489,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
Widget _buildWorkPanel() { Widget _buildWorkPanel() {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) { builder: (context, state) {
print( print('当前DevicesState的pathData: ${state}'); // 调试输出,查看pathData内容
'当前DevicesState的pathData: ${state}',
); // 调试输出,查看pathData内容
// 无选中地块或无路径数据时返回空 // 无选中地块或无路径数据时返回空
if (_selectedPlot == null || state.pathData == null) { if (_selectedPlot == null || state.pathData == null) {
return const SizedBox.shrink(); return const SizedBox.shrink();
@@ -493,22 +498,34 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
// 解析路径数据(根据你的实际数据结构调整) // 解析路径数据(根据你的实际数据结构调整)
List<Map<String, dynamic>> pathRecords = []; List<Map<String, dynamic>> pathRecords = [];
if (state.pathData is List) { if (state.pathData is List) {
pathRecords = state.pathData as List<Map<String, dynamic>>; // 第一步:安全转换为List,并过滤掉非Map的元素
} final List<dynamic> rawList = state.pathData as List<dynamic>;
pathRecords = rawList
.where((item) => item is Map<String, dynamic>)
.cast<Map<String, dynamic>>()
.toList();
// 提取关键信息用于展示 // 第二步:只有列表非空时才赋值第一条数据
String workArea = '0 亩'; if (pathRecords.isNotEmpty) {
int pointCount = 0; _selectedPlotPath = PlotDataPath(jsonData: pathRecords.first);
String workMode = '未知'; } else {
if (pathRecords.isNotEmpty) { _selectedPlotPath = null; // 空列表时清空,避免残留旧数据
final record = pathRecords.first; }
workArea = record['workingArea']?.toString() ?? '0 亩'; } else {
pointCount = record['plotPoints'] != null _selectedPlotPath = null; // 非List类型时清空
? (record['plotPoints'] as List).length
: 0;
workMode = record['workMode'] ?? '未知';
} }
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( return Positioned(
left: 0, left: 0,
right: 0, right: 0,
@@ -570,21 +587,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 4), 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( Text(
'作业模式:$workMode', '作业模式:$workMode',
style: const TextStyle( style: const TextStyle(
@@ -657,7 +660,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
// 3. 开始作业按钮(加载中禁用) // 3. 开始作业按钮(加载中禁用)
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: 48, height: 50,
child: ElevatedButton( child: ElevatedButton(
onPressed: state.isLoading || pathRecords.isEmpty onPressed: state.isLoading || pathRecords.isEmpty
? null ? null
@@ -963,6 +966,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
setState(() { setState(() {
_isListBoxOpen = isOpen; _isListBoxOpen = isOpen;
_isWorkPanelOpen = false;
}); });
}, },
onWorkModeSelected: (mode) { onWorkModeSelected: (mode) {