import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:wonders/common_libs.dart'; import 'package:wonders/logic/artifact_api_logic.dart'; import 'package:wonders/logic/artifact_api_service.dart'; import 'package:wonders/logic/collectibles_logic.dart'; import 'package:wonders/logic/native_widget_service.dart'; import 'package:wonders/logic/locale_logic.dart'; import 'package:wonders/logic/timeline_logic.dart'; import 'package:wonders/logic/unsplash_logic.dart'; import 'package:wonders/logic/wonders_logic.dart'; import 'package:wonders/ui/common/app_shortcuts.dart'; void main() async { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); // Keep native splash screen up until app is finished bootstrapping FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); GoRouter.optionURLReflectsImperativeAPIs = true; // Start app registerSingletons(); runApp(WondersApp()); await appLogic.bootstrap(); // Remove splash screen when bootstrap is complete FlutterNativeSplash.remove(); } /// Creates an app using the [MaterialApp.router] constructor and the global `appRouter`, an instance of [GoRouter]. class WondersApp extends StatelessWidget with GetItMixin { WondersApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final locale = watchX((SettingsLogic s) => s.currentLocale); return MaterialApp.router( routeInformationProvider: appRouter.routeInformationProvider, routeInformationParser: appRouter.routeInformationParser, locale: locale == null ? null : Locale(locale), debugShowCheckedModeBanner: false, routerDelegate: appRouter.routerDelegate, shortcuts: AppShortcuts.defaults, theme: ThemeData(fontFamily: $styles.text.body.fontFamily, useMaterial3: true), color: $styles.colors.black, localizationsDelegates: const [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: AppLocalizations.supportedLocales, ); } } /// Create singletons (logic and services) that can be shared across the app. void registerSingletons() { // Top level app controller GetIt.I.registerLazySingleton(() => AppLogic()); // Wonders GetIt.I.registerLazySingleton(() => WondersLogic()); // Timeline / Events GetIt.I.registerLazySingleton(() => TimelineLogic()); // Search GetIt.I.registerLazySingleton(() => ArtifactAPILogic()); GetIt.I.registerLazySingleton(() => ArtifactAPIService()); // Settings GetIt.I.registerLazySingleton(() => SettingsLogic()); // Unsplash GetIt.I.registerLazySingleton(() => UnsplashLogic()); // Collectibles GetIt.I.registerLazySingleton(() => CollectiblesLogic()); // Localizations GetIt.I.registerLazySingleton(() => LocaleLogic()); // Home Widget Service GetIt.I.registerLazySingleton(() => NativeWidgetService()); } /// Add syntax sugar for quickly accessing the main "logic" controllers in the app /// We deliberately do not create shortcuts for services, to discourage their use directly in the view/widget layer. AppLogic get appLogic => GetIt.I.get(); WondersLogic get wondersLogic => GetIt.I.get(); TimelineLogic get timelineLogic => GetIt.I.get(); SettingsLogic get settingsLogic => GetIt.I.get(); UnsplashLogic get unsplashLogic => GetIt.I.get(); ArtifactAPILogic get artifactLogic => GetIt.I.get(); CollectiblesLogic get collectiblesLogic => GetIt.I.get(); LocaleLogic get localeLogic => GetIt.I.get(); /// Global helpers for readability AppLocalizations get $strings => localeLogic.strings; AppStyle get $styles => WondersAppScaffold.style;