From 0148ff0fc774fbcfcdeec34e9bb06fc7e9238395 Mon Sep 17 00:00:00 2001 From: Songzex <2402265378@qq.com> Date: Sat, 28 Feb 2026 10:51:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generate_path_repository_Impl.dart | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) 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'); } } + }