临时
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:maibu_satabot_v2/common.dart';
|
||||
|
||||
import '../../../../../core/storage/user_storage.dart';
|
||||
import '../../models/device_add_path_point_model.dart';
|
||||
import '../path_http_datasource.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
final UserStorage _userStorage;
|
||||
|
||||
PathHttpDatasourceImpl(this._userStorage);
|
||||
@@ -17,35 +20,33 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('https://servicepathplan.satabot.com/api/path'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': token,
|
||||
},
|
||||
headers: {'Content-Type': 'application/json', 'Authorization': token},
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
//debugPrint('请求体: ${jsonEncode(body)}');
|
||||
|
||||
print('响应体: ${response.body}');
|
||||
// 🔥 完整打印响应体
|
||||
//printFullString(formatJson(jsonEncode(response.body)));
|
||||
try {
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (decoded['success'] == true) {
|
||||
final pathJson = decoded['data']?['path'];
|
||||
print('路径数据: $pathJson'); // 调试输出路径数据
|
||||
if (pathJson == null) {
|
||||
throw Exception('API returned null for "path"');
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (decoded['success'] == true) {
|
||||
final pathJson = decoded['data']?['path'];
|
||||
print('路径数据: $pathJson'); // 调试输出路径数据
|
||||
if (pathJson == null) {
|
||||
throw Exception('API returned null for "path"');
|
||||
}
|
||||
if (pathJson is! List) {
|
||||
throw Exception('Expected "path" to be a List, but got ${pathJson.runtimeType}');
|
||||
}
|
||||
final List<dynamic> jsonData = pathJson;
|
||||
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
|
||||
} else {
|
||||
final apiCode = decoded['code'] ?? -1;
|
||||
final msg = decoded['msg'] ?? '未知错误';
|
||||
throw Exception('API 错误 [$apiCode]: $msg');
|
||||
}
|
||||
if (pathJson is! List) {
|
||||
throw Exception('Expected "path" to be a List, but got ${pathJson.runtimeType}');
|
||||
}
|
||||
final List<dynamic> jsonData = pathJson;
|
||||
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
|
||||
} else {
|
||||
final apiCode = decoded['code'] ?? -1;
|
||||
final msg = decoded['msg'] ?? '未知错误';
|
||||
throw Exception('API 错误 [$apiCode]: $msg');
|
||||
} catch (e) {
|
||||
throw Exception('Network error: $e');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user