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/collectibles_logic.dart'; import 'package:wonders/logic/locale_logic.dart'; import 'package:wonders/logic/met_api_logic.dart'; import 'package:wonders/logic/met_api_service.dart'; import 'package:wonders/logic/timeline_logic.dart'; import 'package:wonders/logic/unsplash_logic.dart'; import 'package:wonders/logic/wallpaper_logic.dart'; import 'package:wonders/logic/wonders_logic.dart'; void main() async { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); // Keep native splash screen up until app is finished bootstrapping FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); // 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 `appRouter`, an instance of [GoRouter]. class WondersApp extends StatelessWidget { const WondersApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp.router( debugShowCheckedModeBanner: false, routerDelegate: appRouter.routerDelegate, routeInformationProvider: appRouter.routeInformationProvider, routeInformationParser: appRouter.routeInformationParser, theme: ThemeData(fontFamily: $styles.text.body.fontFamily), localizationsDelegates: const [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: AppLocalizations.supportedLocales, ); } } /// Create singletons (controllers 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(() => MetAPILogic()); GetIt.I.registerLazySingleton(() => MetAPIService()); // Settings GetIt.I.registerLazySingleton(() => SettingsLogic()); // Unsplash GetIt.I.registerLazySingleton(() => UnsplashLogic()); // Collectibles GetIt.I.registerLazySingleton(() => CollectiblesLogic()); // Localizations GetIt.I.registerLazySingleton(() => LocaleLogic()); } /// Add syntax sugar for quickly accessing the main logical 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(); MetAPILogic get metAPILogic => GetIt.I.get(); CollectiblesLogic get collectiblesLogic => GetIt.I.get(); WallPaperLogic get wallpaperLogic => GetIt.I.get(); LocaleLogic get localeLogic => GetIt.I.get(); AppLocalizations get $strings => localeLogic.strings;