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; | ||||
| 
 | ||||
| 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()); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user