2020-08-28 20:19:42 +00:00
|
|
|
import 'dart:html' show window, querySelector;
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
final localStorage = window.localStorage;
|
|
|
|
|
2021-03-30 16:54:31 +00:00
|
|
|
Future<void> setTheme([String? theme]) async {
|
|
|
|
theme ??= localStorage['theem'] ??
|
|
|
|
(window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
|
|
? 'dark'
|
|
|
|
: 'light');
|
|
|
|
localStorage['theme'] = theme;
|
|
|
|
querySelector('body')!
|
2020-05-05 12:49:26 +00:00
|
|
|
..classes.clear()
|
2021-03-30 16:54:31 +00:00
|
|
|
..classes.add(theme);
|
2020-05-05 12:49:26 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 01:34:55 +00:00
|
|
|
void enableThemeChanger() {
|
2020-08-28 20:19:42 +00:00
|
|
|
final themes = <String>['light', 'dark', 'nord', 'black'];
|
2020-08-25 01:34:55 +00:00
|
|
|
themes.forEach((theme) =>
|
2021-03-30 16:54:31 +00:00
|
|
|
querySelector('#${theme}Btn')!.onClick.listen((_) => setTheme(theme)));
|
2020-05-05 12:49:26 +00:00
|
|
|
}
|