-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
119 lines (102 loc) 路 3.22 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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:holt_soundboard/routes.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:hive/hive.dart';
import 'package:holt_soundboard/styles/themes.dart';
import 'package:holt_soundboard/providers/theme_provider.dart';
import 'package:holt_soundboard/providers/sounds_provider.dart';
import 'package:holt_soundboard/pages/home_page.dart';
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor: Colors.transparent));
runApp(MyApp());
}
Future _openBoxes() async {
var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
return Future.wait([
Hive.openBox('settings'),
Hive.openBox('favorites'),
]);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(providers: [
ChangeNotifierProvider<ThemeProvider>.value(value: ThemeProvider()),
ChangeNotifierProvider<SoundsProvider>.value(value: SoundsProvider())
],
child: Application()
);
}
}
// Bounce scroll physics
class BounceScrollBehavior extends ScrollBehavior {
@override
getScrollPhysics(_) => const BouncingScrollPhysics();
}
class Application extends StatelessWidget {
Future _openBoxes() async {
var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
return Future.wait([
Hive.openBox('settings'),
Hive.openBox('favorites'),
]);
}
Future _getTheme(BuildContext context) async {
var settingsBox = Hive.box('settings');
var theme = settingsBox.get('theme') ?? 'light';
print("Theme from box: $theme");
var materialTheme;
switch (theme) {
case 'light': {
materialTheme = ThemesStyles.light(context);
break;
}
case 'dark': {
materialTheme = ThemesStyles.dark(context);
break;
}
case 'black': {
materialTheme = ThemesStyles.black(context);
break;
}
default: materialTheme = ThemesStyles.light(context);
}
return materialTheme;
}
@override
Widget build(BuildContext context) {
final ThemeProvider themeProvider = Provider.of<ThemeProvider>(context);
// return MaterialApp(
// debugShowCheckedModeBanner: false,
// // theme: snapshot.hasData ? snapshot.data : ThemesStyles.black(context),
// routes: routes(context),
// home: ScrollConfiguration(
// behavior: BounceScrollBehavior(),
// child: HomePage(),
// )
// );
return FutureBuilder(
future: _openBoxes(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return FutureBuilder(
future: _getTheme(context),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: snapshot.hasData ? snapshot.data : ThemesStyles.black(context),
routes: routes(context),
home: ScrollConfiguration(
behavior: BounceScrollBehavior(),
child: HomePage(),
)
);
}
);
}
);
}
}