forked from pndaza/tipitaka-pali
-
Notifications
You must be signed in to change notification settings - Fork 4
/
theme_change_notifier.dart
205 lines (190 loc) · 7.06 KB
/
theme_change_notifier.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/material.dart';
import 'package:tipitaka_pali/data/flex_theme_data.dart';
import 'package:tipitaka_pali/services/prefs.dart';
import 'package:tipitaka_pali/services/provider/locale_change_notifier.dart';
import '../../utils/font_utils.dart';
class ThemeChangeNotifier extends ChangeNotifier {
ThemeMode themeMode = (Prefs.darkThemeOn) ? ThemeMode.dark : ThemeMode.light;
// ignore: unused_field
int _themeIndex = 1;
bool _useM3 = true;
final List<bool> _isSelected = [true, false, false];
set useM3(bool val) {
_useM3 = val;
notifyListeners();
}
set themeIndex(int val) {
_themeIndex = val;
notifyListeners();
}
List<bool> get isSelected {
for (int x = 0; x < _isSelected.length; x++) {
_isSelected[x] = x == Prefs.selectedPageColor;
}
return _isSelected;
}
bool get isDarkMode => themeMode == ThemeMode.dark;
void toggleTheme(int index) async {
Prefs.selectedPageColor = index;
if (index == 2) {
themeMode = ThemeMode.dark;
Prefs.darkThemeOn = true;
} else {
themeMode = ThemeMode.light;
Prefs.darkThemeOn = false;
}
for (int i = 0; i < _isSelected.length; i++) {
_isSelected[i] = i == index;
}
notifyListeners();
}
void onChangeFontSize(double fontSize) {
Prefs.uiFontSize = fontSize;
notifyListeners();
}
// Returns dark ThemeData made by FlexColorScheme
ThemeData get darkTheme => FlexThemeData.dark(
colors: myFlexSchemes[Prefs.themeIndex].dark,
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
blendLevel: 2,
tabBarStyle: FlexTabBarStyle.forAppBar,
transparentStatusBar: true,
subThemesData: FlexSubThemesData(
appBarScrolledUnderElevation: Prefs.useM3 ? 6 : 0,
blendOnLevel: 15,
useTextTheme: true,
useM2StyleDividerInM3: true,
elevatedButtonSchemeColor: SchemeColor.onPrimaryContainer,
elevatedButtonSecondarySchemeColor: SchemeColor.primaryContainer,
inputDecoratorSchemeColor: SchemeColor.primary,
inputDecoratorBackgroundAlpha: 28,
inputDecoratorRadius: 8.0,
inputDecoratorUnfocusedHasBorder: false,
fabUseShape: true,
fabAlwaysCircular: true,
fabSchemeColor: SchemeColor.secondary,
alignedDropdown: true,
useInputDecoratorThemeInDialogs: true,
drawerWidth: 300,
tabBarIndicatorSize: TabBarIndicatorSize.tab,
cardElevation: Prefs.useM3 ? 2 : 4,
interactionEffects: true,
),
keyColors: Prefs.useM3
? const FlexKeyColors(
useSecondary: true,
useTertiary: true,
keepPrimary: true,
keepSecondary: true,
keepTertiary: true,
)
: null,
tones: FlexTones.candyPop(Brightness.dark),
visualDensity: FlexColorScheme.comfortablePlatformDensity,
textTheme: _textTheme,
useMaterial3: Prefs.useM3,
).copyWith(
// Custom ExpansionTileTheme that removes the extra borders.
expansionTileTheme: const ExpansionTileThemeData(
shape: Border(),
collapsedShape: Border(),
),
);
// Returns light ThemeData made by FlexColorScheme
ThemeData get themeData => FlexThemeData.light(
colors: myFlexSchemes[Prefs.themeIndex].light,
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
blendLevel: 1,
appBarStyle: Prefs.useM3 ? FlexAppBarStyle.surface : null,
tabBarStyle: FlexTabBarStyle.forAppBar,
transparentStatusBar: true,
appBarElevation: Prefs.useM3 ? 3 : 0,
subThemesData: FlexSubThemesData(
appBarScrolledUnderElevation: Prefs.useM3 ? 6 : 0,
blendOnLevel: 8,
blendOnColors: false,
useTextTheme: true,
useM2StyleDividerInM3: true,
elevatedButtonSchemeColor: SchemeColor.onPrimaryContainer,
elevatedButtonSecondarySchemeColor: SchemeColor.primaryContainer,
inputDecoratorSchemeColor: SchemeColor.primary,
inputDecoratorBackgroundAlpha: 23,
inputDecoratorRadius: 8.0,
inputDecoratorUnfocusedHasBorder: false,
fabUseShape: true,
fabAlwaysCircular: true,
fabSchemeColor: SchemeColor.secondary,
alignedDropdown: true,
useInputDecoratorThemeInDialogs: true,
drawerWidth: 300,
chipSelectedSchemeColor:
Prefs.useM3 ? SchemeColor.primaryContainer : null,
tabBarIndicatorSize: TabBarIndicatorSize.tab,
cardElevation: Prefs.useM3 ? 2 : 4,
interactionEffects: true,
),
keyColors: Prefs.useM3
? const FlexKeyColors(
useSecondary: true,
useTertiary: true,
keepPrimary: true,
keepSecondary: true,
keepTertiary: true,
)
: null,
tones: FlexTones.candyPop(Brightness.light),
visualDensity: FlexColorScheme.comfortablePlatformDensity,
textTheme: _textTheme,
useMaterial3: Prefs.useM3,
).copyWith(
// Custom ExpansionTileTheme that removes the extra borders.
expansionTileTheme: const ExpansionTileThemeData(
shape: Border(),
collapsedShape: Border(),
),
);
TextTheme get _textTheme {
// this was changed for getting the laos font to work in the UI section of the
// choose book screen. However, it was decided not to support the Laos fonts unless
// the copyright is properly expressed.
// there seemed to be a little bit of a bug with going from lao script back to other scripts
// if you did, you needed to restart the app. To remedy this.. you can totally remove the code that
// has the fontFamily for TextStyle parameter.
// TODO need to follow up on lao font and test.
final theFont = FontUtils.getfontNameByLocale(
locale: LocaleChangeNotifier().localeString);
return TextTheme(
bodyLarge: TextStyle(
fontSize: Prefs.uiFontSize + 2,
fontWeight: FontWeight.w400,
fontFamily: theFont, // passing the font name
),
bodyMedium: TextStyle(
fontSize: Prefs.uiFontSize,
fontWeight: FontWeight.w400,
fontFamily: theFont, // passing the font name
),
bodySmall: TextStyle(
fontSize: Prefs.uiFontSize - 3,
fontWeight: FontWeight.w400,
fontFamily: theFont, // passing the font name
),
titleLarge: TextStyle(
fontSize: Prefs.uiFontSize + 3,
fontWeight: FontWeight.w600,
fontFamily: theFont, // passing the font name
),
titleMedium: TextStyle(
fontSize: Prefs.uiFontSize + 2,
fontWeight: FontWeight.w600,
fontFamily: theFont, // passing the font name
),
titleSmall: TextStyle(
fontSize: Prefs.uiFontSize,
fontWeight: FontWeight.w600,
fontFamily: theFont, // passing the font name
),
);
}
}