-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.dart
136 lines (122 loc) · 3.99 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:start_note/bloc/app/app.dart';
import 'package:start_note/bloc/compare_table/compare_table_bloc.dart';
import 'package:start_note/data/repositories/note_repository.dart';
import 'package:start_note/data/repositories/note_table_repository.dart';
import 'package:start_note/pages/home_page.dart';
import 'package:start_note/services/logging_service.dart';
import 'package:start_note/theme/application_theme.dart';
import 'bloc/notes/notes.dart';
import 'services/database_service.dart';
import 'services/l10n_service.dart';
void main({bool useMocks = false}) async {
runZoned<Future<void>>(
() async {
await WidgetsFlutterBinding.ensureInitialized();
await LoggingService.initialize();
Database database = await DatabaseService.initialize();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getTemporaryDirectory(),
);
runApp(MyApp(database, useMocks: useMocks));
},
);
}
class MyApp extends StatelessWidget {
const MyApp(this.db, {Key? key, this.useMocks = false}) : super(key: key);
final bool useMocks;
final Database db;
@override
Widget build(BuildContext context) {
INoteRepository noteRepository;
INoteTableRepository noteTableRepository;
// if (useMocks) {
// // MockService mockService = MockService()..initialize();
// // noteRepository = mockService.noteRepository;
// } else {
// }
noteRepository = NoteRepository(db);
noteTableRepository = NoteTableRepository(db);
return AppWrapper(
noteRepository: noteRepository,
noteTableRepository: noteTableRepository,
);
}
}
class AppWrapper extends StatelessWidget {
const AppWrapper({
Key? key,
required this.noteRepository,
required this.noteTableRepository,
}) : super(key: key);
final INoteRepository noteRepository;
final INoteTableRepository noteTableRepository;
@override
Widget build(BuildContext context) {
return MultiRepositoryProvider(
providers: [
RepositoryProvider(create: (ctx) => noteRepository),
RepositoryProvider(create: (ctx) => noteTableRepository),
],
child: StartNote(
noteRepository: noteRepository,
noteTableRepository: noteTableRepository,
),
);
}
}
class StartNote extends StatefulWidget {
const StartNote(
{required this.noteRepository, required this.noteTableRepository});
final INoteRepository noteRepository;
final INoteTableRepository noteTableRepository;
@override
StartNoteState createState() => StartNoteState();
}
class StartNoteState extends State<StartNote> {
late NotesBloc notesBloc;
late AppBloc appBloc;
late CompareTableBloc compareTableBloc;
@override
void initState() {
super.initState();
appBloc = AppBloc();
compareTableBloc = CompareTableBloc(widget.noteTableRepository);
notesBloc = NotesBloc(widget.noteRepository, widget.noteTableRepository)
..add(FetchNotes());
}
@override
void dispose() {
appBloc.close();
notesBloc.close();
compareTableBloc.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(create: (_) => notesBloc),
BlocProvider(create: (_) => appBloc),
BlocProvider(create: (_) => compareTableBloc),
],
child: MaterialApp(
localizationsDelegates: L10nService.delegates,
supportedLocales: L10nService.locales,
locale: L10nService.defaultLocale,
debugShowCheckedModeBanner: false,
title: 'Start Note',
home: const HomePage(),
theme: ApplicationTheme.theme,
),
);
}
}