diff --git a/lib/features/devices/data/repositories/generate_path_repository_Impl.dart b/lib/features/devices/data/repositories/generate_path_repository_Impl.dart index 9392a8d9..acc26bf2 100644 --- a/lib/features/devices/data/repositories/generate_path_repository_Impl.dart +++ b/lib/features/devices/data/repositories/generate_path_repository_Impl.dart @@ -134,37 +134,53 @@ class PathRepositoryImpl implements PathRepository { required String workName, }) async { final timestamp = DateTime.now().millisecondsSinceEpoch; - final url = - Uri.parse( - 'https://serviceri.satabot.com/iot/workRecord/selectByWorkName', - ).replace( - queryParameters: { - 'workName': workName, - '_t': timestamp.toString(), // 防缓存 - }, - ); - print('请求URL: $url'); // 调试输出完整URL,检查参数是否正确附加 + final url = Uri.parse( + 'https://serviceri.satabot.com/iot/workRecord/selectByWorkName', + ).replace( + queryParameters: { + 'workName': workName, + '_t': timestamp.toString(), + }, + ); + print('请求URL: $url'); try { final response = await http.get(url); if (response.statusCode == 200) { final data = jsonDecode(response.body) as Map; - print('响应数据: $data'); // 调试输出响应数据,检查结构和内容 + print('响应数据: $data'); if (data['code'] == 200 && data.containsKey('data')) { - final List records = data['data']; - return List>.from(records); + final dynamic rawData = data['data']; + + // 🔧 关键修复:安全转换为 List + + List> records; + if (rawData is List) { + records = rawData.map((e) { + if (e is Map) { + return Map.from(e); + } + throw Exception('List item is not a Map: ${e.runtimeType}'); + }).toList(); + } else if (rawData is Map) { + records = [Map.from(rawData)]; + } else { + throw Exception('Unexpected data type for "data": ${rawData.runtimeType}'); + } + + + return records; } else { throw Exception('API error: ${data['msg'] ?? 'Unknown'}'); } } else { - throw Exception( - 'HTTP ${response.statusCode}: ${response.reasonPhrase}', - ); + throw Exception('HTTP ${response.statusCode}: ${response.reasonPhrase}'); } } catch (e) { throw Exception('Network error in selectWorkRecordByName: $e'); } } + }