init method
Future<void>
init({
- required String baseUrl,
- Directory? cacheDir,
- String cacheName = 'app_local_data',
- List<
Interceptor> ? interceptors, - BaseOptions? baseOptions,
- bool isDebug = false,
- bool useSystemPrint = false,
- String? printTag,
- CheckNetWork? baseCheckNet,
- List<
String> ? ignoreCacheKeys, - RequestCaptureError? requestCaptureError,
- CacheMode? baseCacheMode,
- HiveCipher? encryptionCipher,
- Map<
String, dynamic> ? baseUrlEnv, - int cacheInvalidationTime = 365 * 24 * 60 * 60 * 1000,
- double debugWindowWidth = 600,
- double debugWindowHeight = 500,
初始化公共属性
baseUrl
地址前缀
interceptors
基础拦截器
Implementation
Future<void> init({
required String baseUrl,
Directory? cacheDir,
String cacheName = 'app_local_data',
List<Interceptor>? interceptors,
BaseOptions? baseOptions,
bool isDebug = false,
bool useSystemPrint = false,
String? printTag,
CheckNetWork? baseCheckNet,
List<String>? ignoreCacheKeys,
RequestCaptureError? requestCaptureError,
CacheMode? baseCacheMode,
HiveCipher? encryptionCipher,
Map<String, dynamic>? baseUrlEnv,
int cacheInvalidationTime = 365 * 24 * 60 * 60 * 1000,
double debugWindowWidth = 600,
double debugWindowHeight = 500
}) async{
WidgetsFlutterBinding.ensureInitialized();
LogUtil.init(isDebug: isDebug, tag: printTag, useSystemPrint: useSystemPrint);
this._baseCheckNet = baseCheckNet;
this._baseCacheMode = baseCacheMode;
this._requestCaptureError = requestCaptureError;
this._cacheInvalidationTime = cacheInvalidationTime;
this._baseIgnoreCacheKeys = ignoreCacheKeys;
if (baseOptions != null) {
_client?.options = baseOptions;
}
/// 以最初 baseUrl 为准
_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.onlyRequest;
LogUtil.v("RxNet 不支持缓存的环境:web");
return;
}
_dataBase = RxNetDataBase();
await RxNetDataBase.initDatabase(
directory: cacheDir,
hiveBoxName: cacheName,
encryptionCipher: encryptionCipher);
debugWindowSizeNotifier = ValueNotifier(Size(debugWindowWidth, debugWindowHeight));
}