1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 05:57:28 +01:00
Jisho-Study-Tool/lib/main.dart

73 lines
1.6 KiB
Dart
Raw Normal View History

2021-12-04 05:13:13 +01:00
2020-06-28 00:39:45 +02:00
import 'package:flutter/material.dart';
2021-08-03 22:02:42 +02:00
2021-12-01 23:09:53 +01:00
import 'bloc/theme/theme_bloc.dart';
2022-01-19 02:10:05 +01:00
import 'routing/router.dart';
2022-01-25 20:15:35 +01:00
import 'services/database.dart';
import 'services/licenses.dart';
import 'services/preferences.dart';
import 'settings.dart';
2021-08-08 23:16:54 +02:00
2021-12-06 20:26:52 +01:00
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
2021-12-01 23:09:53 +01:00
2021-12-06 20:26:52 +01:00
await Future.wait([
setupDatabase(),
setupSharedPreferences(),
]);
2020-06-28 00:39:45 +02:00
registerExtraLicenses();
2021-12-04 05:13:13 +01:00
runApp(const MyApp());
}
2021-07-17 16:11:17 +02:00
class MyApp extends StatefulWidget {
2021-12-06 20:26:52 +01:00
const MyApp({Key? key}) : super(key: key);
2021-07-17 16:11:17 +02:00
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
final ThemeBloc themeBloc = ThemeBloc();
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance?.removeObserver(this);
super.dispose();
}
@override
void didChangePlatformBrightness() {
if (autoThemeEnabled) {
final themeIsDark =
WidgetsBinding.instance?.window.platformBrightness == Brightness.dark;
themeBloc.add(SetTheme(themeIsDark: themeIsDark));
}
super.didChangePlatformBrightness();
}
2020-06-28 00:39:45 +02:00
@override
2020-07-09 20:59:00 +02:00
Widget build(BuildContext context) {
2021-08-08 23:16:54 +02:00
return MultiBlocProvider(
providers: [
BlocProvider(create: (context) => themeBloc),
2021-08-08 23:16:54 +02:00
],
child: BlocBuilder<ThemeBloc, ThemeState>(
2021-12-06 20:26:52 +01:00
builder: (context, themeState) => MaterialApp(
title: 'Jisho Study Tool',
theme: themeState.theme.getMaterialTheme(),
initialRoute: '/',
onGenerateRoute: generateRoute,
),
2021-08-03 22:02:42 +02:00
),
);
}
}