setConfig method
Future<void>
setConfig(
- GlobalConfig config, {
- bool? enableBeta,
- String? channel,
- WindowOptions? windowOptions,
设置app 一些默认参数
Implementation
Future<void> setConfig(
GlobalConfig config, {
bool? enableBeta,
String? channel,
/// desktop
WindowOptions? windowOptions,
}) async {
WidgetsFlutterBinding.ensureInitialized();
if (isDesktop && !isWeb) {
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
}
_config = config;
const env = String.fromEnvironment(UConst.channel);
if (env.isNotEmptyOrNull) {
currentChannel = env;
isBeta = currentChannel == UConst.beta;
}
if (enableBeta != null) isBeta = enableBeta;
if (channel != null) currentChannel = channel;
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
/// 初始化本地储存
await BHP().init();
mainColor = config.mainColor;
final bool isRelease = BHP().getBool(UConst.isRelease) ?? false;
if (isBeta && !isRelease) {
_baseApi = config.betaApi;
final String? localApi = BHP().getString(UConst.localApi);
if (localApi != null && localApi.length > 5) _baseApi = localApi;
isDebugger = BHP().getBool(UConst.isDebugger) ?? true;
} else {
isBeta = false;
_baseApi = config.releaseApi;
}
/// 设置toast
/// Set the toast
GlobalWayUI().toastOptions = config.toastOptions;
/// 设置全局log 是否显示 分割线
GlobalWayUI().logCrossLine = config.logCrossLine;
/// 设置全局 [ModalWindows] 组件配置信息
if (config.modalWindowsOptions != null) {
GlobalWayUI().modalWindowsOptions = config.modalWindowsOptions!;
}
/// 全局 [DialogOptions] 配置信息
if (config.generalDialogOptions != null) {
GlobalWayUI().dialogOptions = config.generalDialogOptions!;
}
/// 全局 [BottomSheetOptions] 配置信息
if (config.bottomSheetOptions != null) {
GlobalWayUI().bottomSheetOptions = config.bottomSheetOptions!;
}
/// 全局 [WheelOptions] 配置信息
if (config.wheelOptions != null) {
GlobalWayUI().wheelOptions = config.wheelOptions!;
}
/// 全局 [LoadingOptions] 配置信息
final loading = config.loadingBuilder?.call(const BaseLoading());
GlobalWayUI().loadingOptions = LoadingOptions(
custom: loading,
style: LoadingStyle.circular,
options: const ModalWindowsOptions(absorbing: true)
.merge(config.loadingModalWindowsOptions));
/// 设置页面转场样式
/// Set the page transition style
GlobalWayUI().pushStyle = config.pushStyle;
}