有两种方式可以获取到
1. 不使用Context
final brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
bool isDarkMode = brightness == Brightness.dark;
注意!如果是在程序入口使用,需要加上下面语句
WidgetsFlutterBinding.ensureInitialized();
2. 使用Context
final brightness = MediaQuery.of(context).platformBrightness;
bool isDarkMode = brightness == Brightness.dark;
OR
final brightness = View.of(context).platformDispatcher.platformBrightness;
bool isDarkMode = brightness == Brightness.dark;