There are two ways:
-
NO
contextrequired. Can be used ininitStatefor example:var brightness = SchedulerBinding.instance.window.platformBrightness; bool isDarkMode = brightness == Brightness.dark;or (as suggested by Moore’s Lawyer)
var brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; bool isDarkMode = brightness == Brightness.dark; -
contextis required:var brightness = MediaQuery.of(context).platformBrightness; bool isDarkMode = brightness == Brightness.dark;