init static method
void
init({
- bool isDebug = false,
- String? baseUrl,
- Dio? dio,
- UpdateApiParser? parser,
- ErrorHandler? errorHandler,
- UpdateAvailableCallback? onUpdateAvailable,
- UpdateDialogBuilder? dialogBuilder,
初始化配置 可以在 App 启动时调用此方法进行全局配置
Implementation
static void init({
bool isDebug = false,
String? baseUrl,
Dio? dio,
UpdateApiParser? parser,
ErrorHandler? errorHandler,
UpdateAvailableCallback? onUpdateAvailable,
UpdateDialogBuilder? dialogBuilder,
}) {
if (!Platform.isAndroid) assert(false, 'Only Android is supported');
instance._isDebugging = isDebug;
if (parser != null) _parser = parser;
if (errorHandler != null) _errorHandler = errorHandler;
if (dialogBuilder != null) {
_dialogBuilder = dialogBuilder;
} else {
// 空则使用默认弹出框
_dialogBuilder = (context, updateInfo, statusNotifier, progressNotifier) => MyUpdateDialog(
updateInfo: updateInfo,
statusNotifier: statusNotifier,
progressNotifier: progressNotifier,
);
}
if (dio != null) {
_dio = dio;
} else {
_dio = Dio(
BaseOptions(
baseUrl: baseUrl ?? '',
connectTimeout: const Duration(seconds: 15),
receiveTimeout: const Duration(seconds: 60 * 30), // 30分钟超时
),
);
_dio.interceptors.add(
InterceptorsWrapper(
onResponse: (response, handler) {
if (isDebug) {
print('响应数据: ${response.data.runtimeType}');
print('响应头 ${response.headers}');
}
return handler.next(response);
},
onError: (error, handler) => debugPrint('错误信息: ${error.message}'),
),
);
}
}