setDefaultConfig method
设置app 一些默认参数
Implementation
Future<void> setDefaultConfig(
ProjectConfig config, {
bool? enableBeta,
String? channel,
}) async {
WidgetsFlutterBinding.ensureInitialized();
_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();
currentColor = config.mainColor;
final bool isRelease = BHP().getBool(UConst.isRelease) ?? false;
if (isBeta && !isRelease) {
_currentApi = config.betaApi;
final String? localApi = BHP().getString(UConst.localApi);
if (localApi != null && localApi.length > 5) _currentApi = localApi;
isDebugger = BHP().getBool(UConst.isDebugger) ?? true;
} else {
isBeta = false;
_currentApi = config.releaseApi;
}
/// 设置toast
/// Set the toast
GlobalOptions().toastOptions = config.toastOptions;
/// 设置全局log 是否显示 分割线
GlobalOptions().logCrossLine = config.logCrossLine;
/// 设置全局 [ModalWindows] 组件配置信息
if (config.modalWindowsOptions != null) {
GlobalOptions().modalWindowsOptions = config.modalWindowsOptions!;
}
/// 全局 [DialogOptions] 配置信息
if (config.generalDialogOptions != null) {
GlobalOptions().dialogOptions = config.generalDialogOptions!;
}
/// 全局 [BottomSheetOptions] 配置信息
if (config.bottomSheetOptions != null) {
GlobalOptions().bottomSheetOptions = config.bottomSheetOptions!;
}
/// 全局 [WheelOptions] 配置信息
if (config.wheelOptions != null) {
GlobalOptions().wheelOptions = config.wheelOptions!;
}
/// 全局 [LoadingOptions] 配置信息
final loading = config.loadingBuilder?.call(const BasicLoading());
GlobalOptions().loadingOptions = LoadingOptions(
custom: loading,
style: LoadingStyle.circular,
options: const ModalWindowsOptions(absorbing: true)
.merge(config.loadingModalWindowsOptions));
/// 设置页面转场样式
/// Set the page transition style
GlobalOptions().pushStyle = config.pushStyle;
/// 图片或者文件缓存地址
final cachePath = _config.cachePath;
if (cachePath == null) {
final appPath = await Curiosity().native.appPath;
if (appPath != null) {
if (isAndroid) {
currentCacheDir = '${appPath.externalCacheDir!}/';
} else if (isIOS) {
currentCacheDir = appPath.temporaryDirectory;
} else if (isMacOS) {
currentCacheDir = appPath.temporaryDirectory;
}
}
} else {
currentCacheDir = cachePath;
}
}