Column(
children: [
Widget1(),
Widget2(),
Expanded(
child: SingleChildScrollView(
child: Container(
child: Column(
children: [
for(var i =0 ;i<categories.length;i++){
DetailsCard(catName: categories[i]);
}
],
),
),
),
),
],
)
In the above code i want to add multiple widgets based on the items in the categories list . But when I try using the for loop i keep getting "The element type ‘Set’ can’t be assigned to the list type ‘Widget’." error.
2
Answers
use
for
statement inside of[...]
like below:do not add
{}
and;
in[...]
statement, it is illegalWhat I usually like to do with iterables is using
.map()
onIterables
(List
,Sets
). For example you could use:If you have other Widgets in the
Column
other than the Widgets made from the iterables you could use the spread operator...
.