Reputation: 1233
I'm new to Flutter. I have Expandable List in my app. I'm having problem with assigning icon to Expandable List's header. Title assigning well. I'm using this to require needed data:
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});
}
After that i pass needed parameters like this:
ExpandableListItem(
header: 'Факультеты',
body: 'news',
icon: Icon(
Icons.ac_unit,
color: Colors.red,
),
),
And when i used it to assign it to header i use this:
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
item.icon
),
SizedBox(width: 8),
Text(
item.header,
style: MainTheme.lightTheme.textTheme.headline2,
)
],
);
And here is the problem. I'm having the error as
"The argument type 'Icon' can't be assigned to the parameter type 'IconData?'". How can i fix this error?
Upvotes: 1
Views: 4000
Reputation: 3450
class ExpandableListItem {
bool isExpanded;
final String header;
final String body;
final Widget icon;
}
ExpandableListItem(
header: 'Факультеты',
body: 'news',
icon: Icon(
Icons.ac_unit,
color: Colors.red,
),
),
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
item.icon,
SizedBox(width: 8),
Text(
item.header,
style: MainTheme.lightTheme.textTheme.headline2,
)
],
);
Upvotes: 0
Reputation: 1968
Here, the problem is that, in the ExpandableListItem class
, you are having a field of type Icon
and it's already an Icon widget. Hence in your Row widget, you don't need to add/create a new Icon widget.
Instead, you can directly use item.icon as an Icon widget.
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
item.icon
,
SizedBox(width: 8),
Text(
item.header,
style: MainTheme.lightTheme.textTheme.headline2,
)
],
);
Upvotes: 1