init method

void init({
  1. required String baseUrl,
  2. int connectTimeout = 1000 * 10,
  3. int receiveTimeout = 1000 * 10,
  4. DSHttpInject? inject,
  5. String? proxyAddress,
})

Dio 初始化 baseUrl BASEURL,请求的基础url connectTimeout 连接超时时间(默认10s) receiveTimeout 接收超时时间(默认10s) inject 拦截处理 proxyAddress 代理处理

Implementation

void init({
  required String baseUrl,
  int connectTimeout = 1000 * 10,
  int receiveTimeout = 1000 * 10,
  DSHttpInject? inject,
  String? proxyAddress,
}) {
  _dio = Dio(BaseOptions(
    baseUrl: baseUrl,
    connectTimeout: connectTimeout,
    receiveTimeout: receiveTimeout,
  ));
  if (inject != null) {
    _dio?.interceptors.add(InterceptorsWrapper(
      onRequest: inject.onRequest,
      onResponse: inject.onResponse,
      onError: inject.onError,
    ));
  }
  if (proxyAddress != null && proxyAddress.isNotEmpty) {
    (_dio?.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (HttpClient client) {
      client.findProxy = (uri) {
        return 'PROXY $proxyAddress';
      };
      client.badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
    };
  }
}