yRunApp function
void
yRunApp({
- required YPage launchPage,
- MaterialColor? primarySwatch,
- required dynamic onYConfig(),
- dynamic builder(
- BuildContext context,
- Widget? child
- ThemeData? theme,
- dynamic onYRan()?,
Implementation
void yRunApp({
required YPage launchPage,
MaterialColor? primarySwatch,
required Function() onYConfig,
Function(BuildContext context, Widget? child)? builder,
ThemeData? theme,
Function()? onYRan,
}) {
onYConfig();
FlutterError.onError = (FlutterErrorDetails details) => yDoCrash(details);
var yThemeData = ThemeData(
primarySwatch: primarySwatch ?? Colors.grey,
useMaterial3: false,
);
yThemeData = yThemeData.copyWith(
platform: TargetPlatform.android,
primaryColor: YConfig.themeColor,
colorScheme: yThemeData.colorScheme.copyWith(secondary: YConfig.themeColor),
);
runZonedGuarded(() async {
runApp(MaterialApp(
title: YConfig.appName,
debugShowCheckedModeBanner: YConfig.DEBUG,
theme: theme ?? yThemeData,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
ChineseCupertinoLocalizations.delegate,
],
localeResolutionCallback: (locale, supportedLocales) {
YLocaleUtils.appLocale_system = locale!;
yRead(YConfig.localizationKey).then((value) {
YLocaleUtils.appLocale = value != null ? Locale(value) : locale;
YConfig.onLocaleLoad(YLocaleUtils.appLocale!);
for (var yPage in yPages) {
if (yPage.mounted && yPage.yIsAlive) yPage.setState(() {});
}
});
return locale;
},
supportedLocales: const [Locale("zh", "CH")],
navigatorObservers: [BotToastNavigatorObserver()],
builder: (context, child) {
final yChild = YDeferredBuilder(
onLoad: () => Deferred_Child.loadLibrary(),
onChild: () => Deferred_Child.YDeferredChild(child: child),
);
return builder == null ? yChild : builder.call(context, yChild);
},
home: YDeferredBuilder(
onLoad: () => Deferred_Widget.loadLibrary(),
onChild: () => Deferred_Widget.YDeferredWidget(page: launchPage),
),
));
yPages.add(launchPage);
onYRan?.call();
}, (Object obj, StackTrace stack) => yDoCrash(stack, obj: obj));
}