forked from pndaza/tipitaka-pali
-
Notifications
You must be signed in to change notification settings - Fork 4
/
theme_change_notifier.dart
139 lines (125 loc) · 4.51 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
import 'package:flutter/material.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:tipitaka_pali/services/prefs.dart';
import 'package:tipitaka_pali/data/flex_theme_data.dart';
import 'package:tipitaka_pali/services/provider/script_language_provider.dart';
import '../../utils/font_utils.dart';
class ThemeChangeNotifier extends ChangeNotifier {
ThemeMode themeMode = (Prefs.darkThemeOn) ? ThemeMode.dark : ThemeMode.light;
// ignore: unused_field
int _themeIndex = 1;
final List<bool> _isSelected = [true, false, false];
set themeIndex(int val) {
_themeIndex = val;
notifyListeners();
}
List<bool> get isSelected {
Prefs.selectedPageColor;
//make sure the list returned is the same as prefs given.
for (int x = 0; x < _isSelected.length; x++) {
_isSelected[x] = x == Prefs.selectedPageColor;
}
return _isSelected;
}
bool get isDarkMode => themeMode == ThemeMode.dark;
toggleTheme(int index) {
themeMode = ThemeMode.light;
for (int buttonIndex = 0; buttonIndex < isSelected.length; buttonIndex++) {
if (buttonIndex == index) {
_isSelected[buttonIndex] = true;
} else {
_isSelected[buttonIndex] = false;
}
}
switch (index) {
case 0:
Prefs.selectedPageColor = 0;
themeMode = ThemeMode.light;
Prefs.darkThemeOn = false;
break;
case 1:
Prefs.selectedPageColor = 1;
themeMode = ThemeMode.light;
Prefs.darkThemeOn = false;
break;
case 2:
Prefs.selectedPageColor = 2;
themeMode = ThemeMode.dark;
Prefs.darkThemeOn = true;
break;
default:
Prefs.selectedPageColor = 0;
themeMode = ThemeMode.light;
Prefs.darkThemeOn = false;
break;
}
notifyListeners();
}
void onChangeFontSize(double fontSize) {
Prefs.uiFontSize = fontSize;
notifyListeners();
}
//returns // flexschemedata
get darkTheme => FlexColorScheme.dark(
// As scheme colors we use the one from our list
// pointed to by the current themeIndex.
colors: myFlexSchemes[Prefs.themeIndex].dark,
// Medium strength surface branding used in this example.
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
visualDensity: FlexColorScheme.comfortablePlatformDensity,
textTheme: _textTheme,
).toTheme;
ThemeData get themeData =>
//ThemeData get themeData=> myFlexSchemes[Prefs.themeIndex].light().toTheme();
FlexColorScheme.light(
// As scheme colors we use the one from our list
// pointed to by the current themeIndex.
colors: myFlexSchemes[Prefs.themeIndex].light,
// Medium strength surface branding used in this example.
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
visualDensity: FlexColorScheme.comfortablePlatformDensity,
textTheme: _textTheme,
).toTheme;
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.
final theFont =
FontUtils.getfontName(script: ScriptLanguageProvider().currentScript);
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
),
);
}
}