Reputation: 202
I have this code:
child: Column(
children: [
Text(i.description),
i.colors.map<Widget>(
(colours) => CheckboxListTile(
title: Text(colors),
value: i[colors],
onChanged: (colors){
setState(() {
i[colors] = colors;
});
},
).toList()
],
)
I want to show checkbuttons for each color present in each object, but it throws this error:
type 'List < Widget>' is not a subtype of type 'Widget'
How can I fix it?
Upvotes: 1
Views: 59
Reputation: 1084
You got the error because Column.children
expects a 'simple' array. But you gave an array with a Text
AND another array (i.colors.map<>(___).toList()
), so you got your error.
Add the spread operator ...
before your list, it will unwrap it :
child: Column(
children: [
Text(i.description),
...i.colors.map<Widget>(
(colours) => CheckboxListTile(
title: Text(colors),
value: i[colors],
onChanged: (colors){
setState(() {
i[colors] = colors;
});
},
).toList()
],
)
Upvotes: 3