Reputation: 123
I am looking a way to detect if OS dark mode is active, using Flutter. I just want my app to follow the OS dark mode setting. I've googling it and most of the topics are about "setting & switching" dark mode, not about detect the OS' dark mode.
Upvotes: 2
Views: 2063
Reputation: 2077
You can use platformBrightness
to detect current mode of OS
bool isDarkMode() {
final darkMode = WidgetsBinding.instance.platformDispatcher.platformBrightness;
if (darkMode == Brightness.dark) {
return true;
} else {
return false;
}
}
Upvotes: 6
Reputation: 170
Try this inside your build method
var brightness = MediaQuery.of(context).platformBrightness;
bool darkModeOn = brightness == Brightness.dark;
Upvotes: 1