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.
38 lines
991 B
38 lines
991 B
2 weeks ago
|
import 'package:dio/dio.dart';
|
||
|
|
||
|
class UserProvider {
|
||
|
final Dio _dio;
|
||
|
|
||
|
// 通过构造函数注入 Dio 实例
|
||
|
UserProvider({required Dio dio}) : _dio = dio;
|
||
|
|
||
|
/// 调用 API 修改用户密码
|
||
|
///
|
||
|
/// @param newPassword 新密码
|
||
|
Future<Response> changePassword(String newPassword) async {
|
||
|
try {
|
||
|
final response = await _dio.post(
|
||
|
'/api/change_password', // 替换为你的修改密码接口地址
|
||
|
data: {
|
||
|
'new_password': newPassword,
|
||
|
},
|
||
|
);
|
||
|
return response;
|
||
|
} on DioException catch (e) {
|
||
|
// 抛出 DioException 以便在控制器中处理
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// 调用 API 获取用户信息
|
||
|
///
|
||
|
/// 这个方法可以用于获取用户的姓名、手机号等信息
|
||
|
Future<Response> getUserInfo() async {
|
||
|
try {
|
||
|
final response = await _dio.get('/api/user_info'); // 替换为你的用户信息接口地址
|
||
|
return response;
|
||
|
} on DioException catch (e) {
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
}
|