init method

void init(
  1. String baseUrl,
  2. int connectTimeout,
  3. int receiveTimeout,
  4. bool isDebug,
)

初始化配置 connectTimeout 链接超时时间 5s receiveTimeout 接收数据的时间 5s isDebug 是否是debug模式,是会开启日志

Implementation

void init(
    String baseUrl, int connectTimeout, int receiveTimeout, bool isDebug) {
  // or new Dio with a BaseOptions instance.
  var options = BaseOptions(
    baseUrl: baseUrl,
    connectTimeout: Duration(seconds: connectTimeout),
    receiveTimeout: Duration(seconds: receiveTimeout),
  );
  _dio = Dio(options);

  ///
  /// 强制信任证书
  ///
  (_dio?.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate =
      (client) {
    client.badCertificateCallback = (cert, host, port) {
      return true;
    };
    if (proxyString != null) {
      client.findProxy = (uri) {
        return proxyString!;
      };
    }
    return client;
  };
  /**
   * 开启请求日志
   */
  if (isDebug) {
    _dio?.interceptors
        .add(LogInterceptor(requestBody: true, responseBody: true));
  }
}