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.
45 lines
1.1 KiB
45 lines
1.1 KiB
import 'package:dio/dio.dart';
|
|
|
|
import 'auth_interceptor.dart';
|
|
import 'nw_api.dart';
|
|
import 'nw_method.dart';
|
|
|
|
class DioManager {
|
|
static final DioManager _shared = DioManager._internal();
|
|
factory DioManager() => _shared;
|
|
|
|
late Dio dio;
|
|
|
|
DioManager._internal() {
|
|
BaseOptions options = BaseOptions(
|
|
baseUrl: NWApi.baseApi,
|
|
contentType: Headers.jsonContentType,
|
|
responseType: ResponseType.json,
|
|
connectTimeout: const Duration(seconds: 30),
|
|
receiveTimeout: const Duration(seconds: 30),
|
|
);
|
|
|
|
dio = Dio(options);
|
|
//fdp
|
|
dio.interceptors.add(AuthInterceptor());
|
|
}
|
|
|
|
// 请求,返回参数为 T
|
|
// method:请求方法,NWMethod.POST等
|
|
// path:请求地址
|
|
// params:请求参数
|
|
Future request<T>(
|
|
NWMethod method,
|
|
String path, {
|
|
Map? params,
|
|
Map<String, dynamic>? queryParameters,
|
|
}) async {
|
|
Response response = await dio.request(
|
|
path,
|
|
data: params,
|
|
queryParameters: queryParameters,
|
|
options: Options(method: nwMethodValues[method]),
|
|
);
|
|
return response.data;
|
|
}
|
|
}
|
|
|