【发布时间】:2021-07-22 05:39:38
【问题描述】:
我是 Flutter 的新手。我的应用程序中有可扩展列表。我在将图标分配给可扩展列表的标题时遇到问题。标题分配好。我正在使用它来要求所需的数据:
class ExpandableListItem {
bool isExpanded;
final String header;
final String body;
final Icon icon; // icon problem
ExpandableListItem(
{this.isExpanded: false,
required this.header,
required this.body,
required this.icon});
}
之后我传递所需的参数,如下所示:
ExpandableListItem(
header: 'Факультеты',
body: 'news',
icon: Icon(
Icons.ac_unit,
color: Colors.red,
),
),
当我用它把它分配给标题时,我用这个:
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
item.icon
),
SizedBox(width: 8),
Text(
item.header,
style: MainTheme.lightTheme.textTheme.headline2,
)
],
);
这就是问题所在。我的错误是
“参数类型'Icon'不能分配给参数类型'IconData?'”。我该如何解决这个错误?
【问题讨论】:
-
item.icon已经是Icon的类型 -
?没看懂
-
直接使用不带图标小部件,在行小部件中传递为:
item.icon。