yRunApp function

void yRunApp({
  1. required YPage launchPage,
  2. MaterialColor? primarySwatch,
  3. required dynamic onYConfig(),
  4. dynamic builder(
    1. BuildContext context,
    2. Widget? child
    )?,
  5. ThemeData? theme,
  6. 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,
    textTheme: TextTheme(
      bodySmall: TextStyle(height: YConfig.textHeight),
      bodyMedium: TextStyle(height: YConfig.textHeight),
      bodyLarge: TextStyle(height: YConfig.textHeight),
    ),
  );
  yThemeData = yThemeData.copyWith(
    platform: TargetPlatform.android,
    primaryColor: YConfig.themeColor,
    colorScheme: yThemeData.colorScheme.copyWith(secondary: YConfig.themeColor),
    dividerTheme: DividerThemeData(
      thickness: 1,
      color: Color.fromARGB(255, 248, 248, 248),
      space: 1,
    ),
  );
  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 = BotToastInit()(context, 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));
}