Jisho-Study-Tool/lib/main.dart

58 lines
1.6 KiB
Dart
Raw Permalink Normal View History

2021-12-04 05:13:13 +01:00
import 'dart:io';
2020-06-28 00:39:45 +02:00
import 'package:flutter/material.dart';
2021-12-04 05:13:13 +01:00
import 'package:get_it/get_it.dart';
2021-07-17 16:11:17 +02:00
import 'package:path/path.dart';
2021-12-01 23:09:53 +01:00
import 'package:path_provider/path_provider.dart';
2021-12-04 05:13:13 +01:00
import 'package:sembast/sembast.dart';
import 'package:sembast/sembast_io.dart';
2021-12-06 20:26:52 +01:00
import 'package:shared_preferences/shared_preferences.dart';
2021-08-03 22:02:42 +02:00
2021-12-01 23:09:53 +01:00
import 'bloc/theme/theme_bloc.dart';
import 'router.dart';
2021-08-08 23:16:54 +02:00
2021-12-06 20:26:52 +01:00
Future<void> setupDatabase() async {
2021-12-04 05:13:13 +01:00
final Directory appDocDir = await getApplicationDocumentsDirectory();
2021-12-06 20:26:52 +01:00
if (!appDocDir.existsSync()) appDocDir.createSync(recursive: true);
final Database database =
await databaseFactoryIo.openDatabase(join(appDocDir.path, 'sembast.db'));
GetIt.instance.registerSingleton<Database>(database);
}
2020-06-28 00:39:45 +02:00
2021-12-06 20:26:52 +01:00
Future<void> setupSharedPreferences() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
GetIt.instance.registerSingleton<SharedPreferences>(prefs);
}
2021-07-17 16:11:17 +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
2021-12-04 05:13:13 +01:00
runApp(const MyApp());
}
2021-07-17 16:11:17 +02:00
2021-12-04 05:13:13 +01:00
class MyApp extends StatelessWidget {
2021-12-06 20:26:52 +01:00
const MyApp({Key? key}) : super(key: key);
2021-07-17 16:11:17 +02:00
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()),
],
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
),
);
}
}