-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
60 lines (54 loc) · 2.1 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
import 'package:count_me_down/database/repos/preferences_repo.dart';
import 'package:count_me_down/models/preferences.dart';
import 'package:count_me_down/pages/create_session_page.dart';
import 'package:count_me_down/pages/graph_page.dart';
import 'package:count_me_down/pages/profile_page.dart';
import 'package:count_me_down/pages/scoreboard_page.dart';
import 'package:count_me_down/pages/session_page.dart';
import 'package:count_me_down/pages/sessions_page.dart';
import 'package:count_me_down/pages/settings_page.dart';
import 'package:count_me_down/pages/start_page.dart';
import 'package:count_me_down/styles.dart' as styles;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Preferences preferences = await getPreferences();
while (preferences.id == null) {
await Future<void>.delayed(const Duration(milliseconds: 100));
preferences = await getPreferences();
}
runApp(
Provider<Preferences>(
create: (_) => preferences,
child: CountMeDownApp(),
),
);
}
class CountMeDownApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Preferences preferences = context.watch<Preferences>();
return MaterialApp(
theme: ThemeData(
primarySwatch: styles.colorToMaterialColor(styles.hotNSweetBlue),
appBarTheme: const AppBarTheme(backgroundColor: styles.hotNSweetBlue),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: preferences.activeSessionId == null ? '/' : 'session',
routes: <String, Widget Function(BuildContext)>{
'/': (_) => StartPage(),
'/settings': (_) => SettingsPage(),
'/sessions': (_) => SessionsPage(),
'/sessions/createSession': (_) => CreateSessionPage(),
'/scoreboard': (_) => const ScoreboardPage(),
'/graph': (_) => const GraphPage(),
'/profile': (_) => const ProfilePage(),
'session': (_) => const SessionPage(),
},
onGenerateRoute: (RouteSettings settings) {
return null;
},
);
}
}