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.
29 lines
725 B
29 lines
725 B
import 'package:dio/dio.dart'; |
|
|
|
class ApiClient { |
|
final Dio _dio; |
|
final String baseUrl; |
|
|
|
ApiClient({required this.baseUrl}) : _dio = Dio(BaseOptions(baseUrl: baseUrl)) { |
|
_dio.interceptors.add(InterceptorsWrapper( |
|
onRequest: (options, handler) { |
|
// 添加认证token等 |
|
return handler.next(options); |
|
}, |
|
onError: (error, handler) { |
|
// 统一错误处理 |
|
return handler.next(error); |
|
}, |
|
)); |
|
} |
|
|
|
Future<Response> get(String path, {Map<String, dynamic>? params}) async { |
|
return _dio.get(path, queryParameters: params); |
|
} |
|
|
|
Future<Response> post(String path, dynamic data) async { |
|
return _dio.post(path, data: data); |
|
} |
|
|
|
// 其他HTTP方法... |
|
} |