Reputation: 1747
I have the following code to create Row widgets based on a returned items from Future Builder
for (int i = 0; i < snapshot.data.length; i++) Row( ) ,
the above will create Rows based on the number of items from snapshot.data
what I'm trying to achieve is create multiple widget based on the length of items returned
for (int i = 0; i < snapshot.data.length; i++) {
// for each item create two rows for example
Row( ) ,
Row( ) ,
}
but I get the following error !
the element Type 'set<Row>' can't be assigned to the list 'Widget'
Upvotes: 1
Views: 319
Reputation: 1067
You either use a listView.builder
or for in. When you're building a widget you can't use curly braces
Upvotes: 1
Reputation: 519
Use ListView.builder defining the length to itemCount property. For Example..
body: ListView.builder
(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext ctxt, int index) {
return Row();
}
)
Upvotes: 1
Reputation: 336
Try this one:
List.generate(snapshot.data.length, (index) => Row( ),),
or if you want to insert deferent widget at deferent index use:
List.generate(snapshot.data.length, (index) {
if(index == 0){return Row();}
else if(index == 1){return Column();}
else{return Container();}
),
Upvotes: 1