如何检查Flutter中是否启用了Android或iOS暗模式?

如何检查Flutter中是否启用了Android或iOS暗模式?

问题描述:

如何通过 Flutter 检查 Android Q 中是否启用了暗模式?
我知道如何设置暗模式,但是我没有找到一种检查背景主题的方法。

这是设置黑暗主题的代码。

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(),


我找到了方法。

  bool _darkModeEnabled = false;

  void _checkIfDarkModeEnabled() {
    final ThemeData theme = Theme.of(context);
    theme.brightness == appDarkTheme().brightness
        ? _darkModeEnabled = true
        : _darkModeEnabled = false;
  }