item.header的常量错误消息无效。
它是一个布尔值,表示列表块将使用粗体还是普通字体粗细。
child: ListTile(
key: ValueKey(item.stuffId),
title: Text(
item.name,
style: const TextStyle(
color: Colors.blue,
fontWeight: item.header == true ? FontWeight.bold : FontWeight.normal,
),
),
下面是我使用的列表:
final List<Stuff> _items = [
Stuff(stuffId: "1", name: "Toiletries", header: true),
Stuff(stuffId: "2", name: "Toothpaste", header: false),
Stuff(stuffId: "3", name: "Hair brush", header: false),
Stuff(stuffId: "4", name: "Nail clippers", header: false),
];
enter image description here
“化妆品”是标题,因此应该是粗体。
2条答案
按热度按时间dgsult0t1#
vh0rcniy2#
item.header
将获取/检查运行时,它不能是常量,请删除const
了解更多关于What is the difference between the "const" and "final" keywords in Dart?的信息