我正在尝试设置黑暗模式,但主题小部件无效
我无法确定原因,没有错误
Theme(
data: _darkMode //true & false by setState
? ThemeData(
backgroundColor: Colors.black,
primaryTextTheme: TextTheme(
display1: TextStyle(color: Colors.white),
),
)
: ThemeData(
primaryColor: Colors.white,
primaryTextTheme: TextTheme(
display1: TextStyle(color: Colors.black),
),
),
child: Container(
child: Column(children: <Widget>[
Text("Text 1 .."),
Text("Text 2 ..")
],
),
),
最佳答案
您可以使用 brightness
属性创建暗模式效果。
Theme(
brightness: Brightness.dark,
child: MyApp(),
),
查阅这篇文章,其中有许多有关使用深色主题的信息:Dark Mode in Flutter
关于flutter - 主题小部件无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60288804/