Issue
How can I check if dark mode is enabled in Android Q with Flutter?
I know how to set the dark mode, but I didn't find a way to check the background theme.
Here is the code to set the dark theme.
darkTheme: ThemeData.dark(),
Solution
There are two ways:
NO
context
required. Can be used ininitState
for example:var brightness = SchedulerBinding.instance!.window.platformBrightness; bool isDarkMode = brightness == Brightness.dark;
context
is required:var brightness = MediaQuery.of(context).platformBrightness; bool isDarkMode = brightness == Brightness.dark;
Answered By - CopsOnRoad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.