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: connectTimeout * 1000,
    receiveTimeout: receiveTimeout * 1000,
  );
  _dio = Dio(options);

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