@@ -18,6 +18,55 @@ import 'package:http/io_client.dart';
18
18
import 'package:jaguar_retrofit/jaguar_retrofit.dart' ;
19
19
import 'package:shared_preferences/shared_preferences.dart' ;
20
20
21
+ /// Describes the contrast needs of a color.
22
+ class AppBrightness {
23
+ final index;
24
+ const AppBrightness ._internal (this .index);
25
+ toString () => 'AppBrightness.$index ' ;
26
+
27
+ /// The color is dark and will require a light text color to achieve readable
28
+ /// contrast.
29
+ ///
30
+ /// For example, the color might be dark grey, requiring white text.
31
+
32
+ static const dark = const AppBrightness ._internal (0 );
33
+
34
+ /// The color is light and will require a dark text color to achieve readable
35
+ /// contrast.
36
+ ///
37
+ /// For example, the color might be bright white, requiring black text.
38
+
39
+ static const light = const AppBrightness ._internal (1 );
40
+
41
+ /// The color is black and will require a light text color to achieve readable
42
+ /// contrast.
43
+ ///
44
+ /// For example, the color might be black, requiring white text.
45
+ static const black = const AppBrightness ._internal (2 );
46
+
47
+ static const values = [dark, light, black];
48
+
49
+ Brightness toBrightness () {
50
+ return index == 2 ? Brightness .dark : Brightness .values[index];
51
+ }
52
+
53
+ // // You should generally implement operator == if you
54
+ // // override hashCode.
55
+ // @override
56
+ // bool operator ==(dynamic other) {
57
+ // if (other is! AppBrightness) {
58
+ // if (other is! Brightness) {
59
+ // return false;
60
+ // }
61
+ // Brightness brightness = other;
62
+ // return brightness.index == index || (index == 2 && brightness.index == 1);
63
+ // }
64
+ // AppBrightness appBrightness = other;
65
+ // return appBrightness.index == index;
66
+ // }
67
+
68
+ }
69
+
21
70
class InstiAppBloc {
22
71
// Different Streams for the state
23
72
Stream <UnmodifiableListView <Hostel >> get hostels => _hostelsSubject.stream;
@@ -50,15 +99,15 @@ class InstiAppBloc {
50
99
String homepageName = "/mess" ;
51
100
52
101
// default theme
53
- Brightness _brightness = Brightness .light;
102
+ AppBrightness _brightness = AppBrightness .light;
54
103
// Color _primaryColor = Color.fromARGB(255, 63, 81, 181);
55
104
Color _primaryColor = Color .fromARGB (255 , 0 , 98 , 255 );
56
105
Color _accentColor = Color .fromARGB (255 , 239 , 83 , 80 );
57
106
// Color _accentColor = Color.fromARGB(255, 139, 195, 74);
58
107
59
- Brightness get brightness => _brightness;
108
+ AppBrightness get brightness => _brightness;
60
109
61
- set brightness (Brightness newBrightness) {
110
+ set brightness (AppBrightness newBrightness) {
62
111
if (newBrightness != _brightness) {
63
112
wholeAppKey.currentState.setTheme (() => _brightness = newBrightness);
64
113
SharedPreferences .getInstance ().then ((s) {
@@ -103,7 +152,7 @@ class InstiAppBloc {
103
152
'/quicklinks' : 9 ,
104
153
'/settings' : 10 ,
105
154
};
106
-
155
+
107
156
// MaterialApp reference
108
157
GlobalKey <MyAppState > wholeAppKey;
109
158
@@ -131,7 +180,8 @@ class InstiAppBloc {
131
180
drawerState.setPageIndex (pageToIndex[homepageName]);
132
181
}
133
182
if (prefs.getKeys ().contains ("brightness" )) {
134
- _brightness = Brightness .values[prefs.getInt ("brightness" )] ?? _brightness;
183
+ _brightness =
184
+ AppBrightness .values[prefs.getInt ("brightness" )] ?? _brightness;
135
185
}
136
186
if (prefs.getKeys ().contains ("accentColor" )) {
137
187
_accentColor = Color (prefs.getInt ("accentColor" )) ?? _accentColor;
0 commit comments