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:
Lucien Cartier-Tilet 2020-05-21 07:34:10 +02:00
parent d69682ec06
commit 9725e24b38
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -21,8 +21,6 @@ final themes = {
final localStorage = window.localStorage;
var currentTheme = themes[localStorage['theme']];
void enableThemeChanger() {
final darkBtn = querySelector('#darkBtn');
final lightBtn = querySelector('#lightBtn');
@ -34,10 +32,12 @@ void enableThemeChanger() {
}
Future<void> setTheme() async {
if (currentTheme == null) {
currentTheme = themes['light'];
localStorage['theme'] = currentTheme.getName();
}
final currentTheme = themes[localStorage['theme']] ??
() {
final devicePrefersDark =
window.matchMedia('(prefers-color-scheme: dark)').matches;
return themes[devicePrefersDark ? 'dark' : 'light'];
}();
querySelector('body')
..classes.clear()
..classes.add(currentTheme.getName());