Skip to content

Commit 0654e8e

Browse files
theme mode and accent color
1 parent 6a47179 commit 0654e8e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

lib/utils/my_states.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:text_to_image_gen/utils/prefs_manager.dart';
3+
4+
class ThemeState extends ChangeNotifier {
5+
int currentThemeIndex = 0;
6+
ThemeMode currentThemeMode = ThemeMode.light;
7+
final List<ThemeMode> _themeModes = [
8+
ThemeMode.light,
9+
ThemeMode.dark,
10+
ThemeMode.system
11+
];
12+
void getTheme() async {
13+
currentThemeIndex = await PrefManager().getThemeIndex();
14+
currentThemeMode = _themeModes[currentThemeIndex];
15+
currentAccentIndex = await PrefManager().getAccentIndex();
16+
currentAccent = accentColors[currentAccentIndex];
17+
notifyListeners();
18+
}
19+
20+
changeThemeMode(index) {
21+
currentThemeMode = _themeModes[index];
22+
currentThemeIndex = index;
23+
notifyListeners();
24+
PrefManager().saveThemeIndex(index);
25+
}
26+
27+
ThemeData getDarkTheme() {
28+
return ThemeData(
29+
useMaterial3: true,
30+
brightness: Brightness.dark,
31+
colorSchemeSeed: currentAccent,
32+
);
33+
}
34+
35+
ThemeData getLightTheme() {
36+
return ThemeData(
37+
useMaterial3: true,
38+
colorSchemeSeed: currentAccent,
39+
);
40+
}
41+
42+
// For Accent colors
43+
int currentAccentIndex = 0;
44+
List<Color> accentColors = [
45+
Colors.amber,
46+
Colors.purple,
47+
Colors.cyan,
48+
Colors.greenAccent,
49+
Colors.lime,
50+
Colors.redAccent
51+
];
52+
List<Text> accentTexts = [
53+
const Text("Amber"),
54+
const Text("Purple"),
55+
const Text("Cyan"),
56+
const Text("Green Accent"),
57+
const Text("Lime"),
58+
const Text("Red Accent")
59+
];
60+
Color currentAccent = Colors.amber;
61+
62+
changeAccent(index) {
63+
currentAccent = accentColors[index];
64+
currentAccentIndex = index;
65+
notifyListeners();
66+
PrefManager().saveAccentIndex(index);
67+
}
68+
}

0 commit comments

Comments
 (0)