initNet method

Future<void> initNet({
  1. required String baseUrl,
  2. Directory? cacheDir,
  3. String cacheName = 'app_local_data',
  4. CacheMode baseCacheMode = CacheMode.ONLY_REQUEST,
  5. List<Interceptor>? interceptors,
  6. BaseOptions? baseOptions,
  7. bool systemLog = false,
  8. CheckNetWork? baseCheckNet,
  9. List<String>? ignoreCacheKeys,
  10. HiveCipher? encryptionCipher,
  11. Map<String, dynamic>? baseUrlEnv,
  12. int cacheInvalidationTime = 365 * 24 * 60 * 60 * 1000,
  13. double debugWindowWidth = 800,
  14. double debugWindowHeight = 600,
})

Implementation

Future<void> initNet({
  required String baseUrl,
  Directory? cacheDir,
  String cacheName = 'app_local_data',
  CacheMode baseCacheMode = CacheMode.ONLY_REQUEST,
  List<Interceptor>? interceptors,
  BaseOptions? baseOptions,
  bool systemLog = false,
  CheckNetWork? baseCheckNet,
  List<String>? ignoreCacheKeys,
  HiveCipher? encryptionCipher,
  Map<String, dynamic>? baseUrlEnv,
  int cacheInvalidationTime = 365 * 24 * 60 * 60 * 1000,
  double debugWindowWidth = 800,
  double debugWindowHeight = 600
}) async {
  LogUtil.init(systemLog: systemLog);

  this._baseCheckNet = baseCheckNet;
  this._baseCacheMode = baseCacheMode;
  this._cacheInvalidationTime = cacheInvalidationTime;
  this._baseIgnoreCacheKeys = ignoreCacheKeys;
  debugWindow = ValueNotifier(Size(debugWindowWidth, debugWindowHeight));

  if (baseOptions != null) {
    _client?.options = baseOptions;
  }

  _client?.options.baseUrl = baseUrl;
  if (interceptors != null) {
    _client?.interceptors.addAll(interceptors);
  }
  if (baseUrlEnv != null && baseUrlEnv.isNotEmpty) {
    _baseUrlEnv.addAll(baseUrlEnv);
  }
  if (RxNetPlatform.isWeb) {
    this._baseCacheMode = CacheMode.ONLY_REQUEST;
    LogUtil.v("RxNet does not support caching environments: web");
    LogUtil.v("RxNet 不支持缓存的环境:web");
    return;
  }
  await cacheManager.init(cacheDir, cacheName, encryptionCipher);
}