init method

void init()

Implementation

void init() {
  var options = BaseOptions(
      baseUrl: _config.baseUrl,
      headers: _config.headers,
      receiveTimeout: _config.receiveTimeout ?? const Duration(seconds: 5),
      connectTimeout: _config.connectTimeout ?? const Duration(seconds: 5),
      sendTimeout: _config.sendTimeout ?? const Duration(seconds: 5));
  KHttpPlatform.get.successCode = _config.successCode;
  _dio = Dio(options);

  //cookie 配置
  if (_config.cookiesPath?.isNotEmpty ?? false) {
    _dio.interceptors.add(CookieManager(
        PersistCookieJar(storage: FileStorage(_config.cookiesPath))));
  }

  // 增加app 拦截器用于业务处理
  _dio.interceptors.add(TokenIntercepter());

  //日志配置
  if (_config.showLog) {
    _dio.interceptors.add(PrettyDioLogger(
        requestHeader: true,
        requestBody: true,
        responseBody: true,
        responseHeader: false,
        error: true,
        compact: true,
        maxWidth: 100));
  }
}