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
contextrequired. Can be used ininitStatefor example:var brightness = SchedulerBinding.instance!.window.platformBrightness; bool isDarkMode = brightness == Brightness.dark;contextis 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.