21 lines
587 B
Dart
21 lines
587 B
Dart
import 'dart:html' show window, querySelector;
|
|
|
|
final localStorage = window.localStorage;
|
|
|
|
Future<void> setTheme([String? theme]) async {
|
|
theme ??= localStorage['theem'] ??
|
|
(window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
? 'dark'
|
|
: 'light');
|
|
localStorage['theme'] = theme;
|
|
querySelector('body')!
|
|
..classes.clear()
|
|
..classes.add(theme);
|
|
}
|
|
|
|
void enableThemeChanger() {
|
|
final themes = <String>['light', 'dark', 'nord', 'black'];
|
|
themes.forEach((theme) =>
|
|
querySelector('#${theme}Btn')!.onClick.listen((_) => setTheme(theme)));
|
|
}
|