如何检查Flutter中是否启用了Android或iOS暗模式? [英] How to check if Android or iOS dark mode is enabled in Flutter?

查看:114
本文介绍了如何检查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;
  }

这篇关于如何检查Flutter中是否启用了Android或iOS暗模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆