【发布时间】:2019-11-29 10:50:28
【问题描述】:
我刚开始使用 Flutter,只是在尝试一些东西。 我设置了一个自定义主题,但是 ListTile 的 title 属性下的 Text Widgets 没有得到正确的颜色。此外,领先属性下的图标也没有得到正确的颜色。
我尝试设置一些其他颜色,并整理出来,问题只存在于该元素中。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
theme: ThemeData(
primaryColor: Colors.black,
scaffoldBackgroundColor: Color(0xff202020),
cardTheme: CardTheme(color: Colors.black),
textTheme: TextTheme(
body1: TextStyle(color: Colors.white),
subtitle: TextStyle(color: Colors.white),
headline: TextStyle(color: Colors.white)),
iconTheme: IconThemeData(color: Colors.white)),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
HomePageState createState() => new HomePageState();
}
class HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("HomePage"),
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
tooltip: "back to the last page.",
onPressed: () {
Navigator.pop(context);
})
),
body: Card(
child: ListTile(
title: Text("Test"),
leading: new Icon(Icons.devices)
),
));
}
}
标题的文本应该和图标一样显示为白色,而不是黑色。所有其他文本都是白色的。
【问题讨论】:
-
使用
caption而不是subtitle属性为TextTheme更改ListTile的subtitle颜色。