updateUserProfile static method
更新用户画像
Implementation
static Future<UserProfileModel?> updateUserProfile(UserProfileModel profile) async {
final url = '${EnvironmentConfig.baseUrl}$_updateProfilePath';
print('========== 📤 更新用户画像请求 ==========');
print('🔗 请求地址: $url');
print('📦 请求体: ${json.encode(profile.toJson())}');
try {
final response = await http.post(
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
},
body: json.encode(profile.toJson()),
).timeout(
Duration(seconds: EnvironmentConfig.apiTimeout),
onTimeout: () {
throw Exception('更新用户画像请求超时');
},
);
print('✅ 收到更新用户画像响应 (状态码: ${response.statusCode})');
print('📄 响应体: ${response.body}');
if (response.statusCode == 200) {
final Map<String, dynamic> responseData = json.decode(response.body);
if (responseData['success'] == true && responseData['data'] != null) {
print('✅ 用户画像更新成功');
return UserProfileModel.fromJson(responseData['data']);
} else {
print('❌ 用户画像更新失败: ${responseData['error']}');
return null;
}
} else {
print('❌ 更新用户画像失败: ${response.statusCode}');
return null;
}
} catch (e) {
print('❌ 更新用户画像异常: $e');
return null;
}
}