Fixes #8
The default theme is now chosen based on the user’s preference stored in their device. If the device uses a dark theme, the website’s dark theme will be used by default. Otherwise, the light theme will be used by default.
This commit is contained in:
parent
d69682ec06
commit
9725e24b38
@ -21,8 +21,6 @@ final themes = {
|
|||||||
|
|
||||||
final localStorage = window.localStorage;
|
final localStorage = window.localStorage;
|
||||||
|
|
||||||
var currentTheme = themes[localStorage['theme']];
|
|
||||||
|
|
||||||
void enableThemeChanger() {
|
void enableThemeChanger() {
|
||||||
final darkBtn = querySelector('#darkBtn');
|
final darkBtn = querySelector('#darkBtn');
|
||||||
final lightBtn = querySelector('#lightBtn');
|
final lightBtn = querySelector('#lightBtn');
|
||||||
@ -34,10 +32,12 @@ void enableThemeChanger() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setTheme() async {
|
Future<void> setTheme() async {
|
||||||
if (currentTheme == null) {
|
final currentTheme = themes[localStorage['theme']] ??
|
||||||
currentTheme = themes['light'];
|
() {
|
||||||
localStorage['theme'] = currentTheme.getName();
|
final devicePrefersDark =
|
||||||
}
|
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
return themes[devicePrefersDark ? 'dark' : 'light'];
|
||||||
|
}();
|
||||||
querySelector('body')
|
querySelector('body')
|
||||||
..classes.clear()
|
..classes.clear()
|
||||||
..classes.add(currentTheme.getName());
|
..classes.add(currentTheme.getName());
|
||||||
|
Reference in New Issue
Block a user