mirror of
https://github.com/gskinnerTeam/flutter-wonderous-app.git
synced 2025-05-22 07:16:30 +08:00
Initial public commit
This commit is contained in:
82
lib/main.dart
Normal file
82
lib/main.dart
Normal file
@ -0,0 +1,82 @@
|
||||
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>(() => AppLogic());
|
||||
// Wonders
|
||||
GetIt.I.registerLazySingleton<WondersLogic>(() => WondersLogic());
|
||||
// Timeline / Events
|
||||
GetIt.I.registerLazySingleton<TimelineLogic>(() => TimelineLogic());
|
||||
// Search
|
||||
GetIt.I.registerLazySingleton<MetAPILogic>(() => MetAPILogic());
|
||||
GetIt.I.registerLazySingleton<MetAPIService>(() => MetAPIService());
|
||||
// Settings
|
||||
GetIt.I.registerLazySingleton<SettingsLogic>(() => SettingsLogic());
|
||||
// Unsplash
|
||||
GetIt.I.registerLazySingleton<UnsplashLogic>(() => UnsplashLogic());
|
||||
// Collectibles
|
||||
GetIt.I.registerLazySingleton<CollectiblesLogic>(() => CollectiblesLogic());
|
||||
// Localizations
|
||||
GetIt.I.registerLazySingleton<LocaleLogic>(() => 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<AppLogic>();
|
||||
WondersLogic get wondersLogic => GetIt.I.get<WondersLogic>();
|
||||
TimelineLogic get timelineLogic => GetIt.I.get<TimelineLogic>();
|
||||
SettingsLogic get settingsLogic => GetIt.I.get<SettingsLogic>();
|
||||
UnsplashLogic get unsplashLogic => GetIt.I.get<UnsplashLogic>();
|
||||
MetAPILogic get metAPILogic => GetIt.I.get<MetAPILogic>();
|
||||
CollectiblesLogic get collectiblesLogic => GetIt.I.get<CollectiblesLogic>();
|
||||
WallPaperLogic get wallpaperLogic => GetIt.I.get<WallPaperLogic>();
|
||||
LocaleLogic get localeLogic => GetIt.I.get<LocaleLogic>();
|
||||
AppLocalizations get $strings => localeLogic.strings;
|
Reference in New Issue
Block a user