You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
882 B

import 'package:dio/dio.dart';
import 'package:problem_check_system/data/models/auth_model.dart';
import 'package:problem_check_system/data/providers/dio_provider.dart';
class MyRepository {
final DioProvider dioProvider;
MyRepository({required this.dioProvider});
/// 从 API 获取用户个人资料
Future<Profile> getUserProfile() async {
try {
final response = await dioProvider.get('/api/Accounts/Profile');
// 将 JSON 数据反序列化为 Profile 模型
return Profile.fromJson(response.data);
} on DioException catch (e) {
// 专门处理网络错误,例如无网络连接、超时等
// DioException 包含了更详细的错误信息
throw Exception('Network error: ${e.message}');
} catch (e) {
// 捕获所有其他未知错误
rethrow; // 重新抛出异常,让调用者来处理
}
}
}