【发布时间】:2019-12-31 03:38:52
【问题描述】:
尝试将文本颜色应用于列表视图中的标题图块。我用红色文本颜色定义了标题文本样式(是的,我也尝试过使用 Colors.red)。
创建磁贴时,我使用函数 _headerTile。尝试通过 Theme.of(context).textTheme.headline 加载样式。但是,当我这样做时,文本不使用我在标题中定义的三个属性中的任何一个。
是不是我做错了什么?
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
home: Scaffold(
appBar: AppBar(
title: const Text(
'App',
)),
body: _buildList(context)),
theme: ThemeData(
textTheme: TextTheme(
headline: TextStyle(
color: Color.fromRGBO(255, 0, 0, 1),
fontSize: 72.0,
fontWeight: FontWeight.bold),
),
));
}
}
Widget _buildList(BuildContext context) => ListView(
children: [
_headerTile(context, "About Us")
],
);
ListTile _headerTile(BuildContext context, String title) => ListTile(
title: Text(title,
style: Theme.of(context)
.textTheme
.headline
contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 8),
);
【问题讨论】:
-
你在哪里调用 _headerTile?
-
我的 _buildList 函数。我会添加
标签: flutter