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; 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());