2023-02-06 14:19:55 +00:00
|
|
|
import 'package:anitrack/src/service/database.dart';
|
2023-02-03 22:33:21 +00:00
|
|
|
import 'package:anitrack/src/ui/bloc/anime_list_bloc.dart';
|
|
|
|
import 'package:anitrack/src/ui/bloc/anime_search_bloc.dart';
|
2023-02-04 16:17:00 +00:00
|
|
|
import 'package:anitrack/src/ui/bloc/details_bloc.dart';
|
2023-02-03 22:33:21 +00:00
|
|
|
import 'package:anitrack/src/ui/bloc/navigation_bloc.dart';
|
|
|
|
import 'package:anitrack/src/ui/constants.dart';
|
|
|
|
import 'package:anitrack/src/ui/pages/anime_list.dart';
|
|
|
|
import 'package:anitrack/src/ui/pages/anime_search.dart';
|
2023-02-04 16:17:00 +00:00
|
|
|
import 'package:anitrack/src/ui/pages/details.dart';
|
2023-02-03 22:33:21 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:get_it/get_it.dart';
|
|
|
|
|
2023-02-03 23:25:16 +00:00
|
|
|
void main() async {
|
2023-02-03 22:33:21 +00:00
|
|
|
final navKey = GlobalKey<NavigatorState>();
|
|
|
|
|
2023-02-03 23:25:16 +00:00
|
|
|
// Initialize the widgets binding for sqflite
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
// Initialize the database
|
|
|
|
final database = DatabaseService();
|
|
|
|
await database.initialize();
|
|
|
|
|
|
|
|
// Register singletons
|
|
|
|
GetIt.I.registerSingleton<DatabaseService>(database);
|
2023-02-03 22:33:21 +00:00
|
|
|
GetIt.I.registerSingleton<AnimeListBloc>(AnimeListBloc());
|
|
|
|
GetIt.I.registerSingleton<AnimeSearchBloc>(AnimeSearchBloc());
|
2023-02-04 16:17:00 +00:00
|
|
|
GetIt.I.registerSingleton<DetailsBloc>(DetailsBloc());
|
2023-02-03 22:33:21 +00:00
|
|
|
GetIt.I.registerSingleton<NavigationBloc>(NavigationBloc(navKey));
|
2023-02-03 23:25:16 +00:00
|
|
|
|
|
|
|
// Load animes
|
|
|
|
GetIt.I.get<AnimeListBloc>().add(
|
|
|
|
AnimesLoadedEvent(),
|
|
|
|
);
|
2023-02-03 22:33:21 +00:00
|
|
|
|
|
|
|
runApp(
|
|
|
|
MultiBlocProvider(
|
|
|
|
providers: [
|
|
|
|
BlocProvider<AnimeListBloc>(
|
|
|
|
create: (_) => GetIt.I.get<AnimeListBloc>(),
|
|
|
|
),
|
|
|
|
BlocProvider<AnimeSearchBloc>(
|
|
|
|
create: (_) => GetIt.I.get<AnimeSearchBloc>(),
|
|
|
|
),
|
2023-02-04 16:17:00 +00:00
|
|
|
BlocProvider<DetailsBloc>(
|
|
|
|
create: (_) => GetIt.I.get<DetailsBloc>(),
|
|
|
|
),
|
2023-02-03 22:33:21 +00:00
|
|
|
BlocProvider<NavigationBloc>(
|
|
|
|
create: (_) => GetIt.I.get<NavigationBloc>(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: MyApp(navKey),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp(
|
|
|
|
this.navKey, {
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final GlobalKey<NavigatorState> navKey;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'AniTrack',
|
|
|
|
theme: ThemeData(
|
2023-02-04 11:50:45 +00:00
|
|
|
brightness: Brightness.light,
|
2023-02-03 22:33:21 +00:00
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
|
|
|
darkTheme: ThemeData(
|
2023-02-04 11:50:45 +00:00
|
|
|
brightness: Brightness.dark,
|
2023-02-03 22:33:21 +00:00
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
|
|
|
navigatorKey: navKey,
|
|
|
|
onGenerateRoute: (settings) {
|
|
|
|
switch (settings.name) {
|
|
|
|
case '/':
|
|
|
|
case animeListRoute: return AnimeListPage.route;
|
|
|
|
case animeSearchRoute: return AnimeSearchPage.route;
|
2023-02-04 16:17:00 +00:00
|
|
|
case detailsRoute: return DetailsPage.route;
|
2023-02-03 22:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|