DioRequest constructor

DioRequest({
  1. String? baseUrl,
  2. BaseOptions? op,
  3. LogInterceptor? log,
  4. CacheOptions? cache,
  5. String? cookiePath,
  6. List<Interceptor>? interceptorList,
})

构造方法 如果baseUrl不等于空,options中的baseUrl属性会被这个参数覆盖

Implementation

DioRequest(
    {String? baseUrl,
    BaseOptions? op,
    LogInterceptor? log,
    CacheOptions? cache,
    String? cookiePath,
    List<Interceptor>? interceptorList}) {
  _dio = Dio();
  _dio.options = op ?? DefaultOption(baseUrl: baseUrl);
  if (baseUrl != null && baseUrl.isNotEmpty) {
    _dio.options.baseUrl = baseUrl;
  }
  if (kDebugMode && log != null) {
    _dio.interceptors.add(log);
  }
  if (cache != null) {
    cacheOptions = cache;
    _dio.interceptors.add(DioCacheInterceptor(options: cache));
  }
  if (cookiePath != null && cookiePath.isNotEmpty) {
    cookieJar = PersistCookieJar(storage: FileStorage(cookiePath));
    _dio.interceptors.add(CookieManager(cookieJar!));
  }
  if (interceptorList != null && interceptorList.isNotEmpty) {
    _dio.interceptors.addAll(interceptorList);
  }
}