How can I return multiple widgets using for loop?

1,075 views
Skip to first unread message

Souvik Dutta

unread,
Mar 31, 2020, 8:50:25 AM3/31/20
to flutt...@googlegroups.com
Hi, 
The question might be childish but it's really bothering me. I have a listview.builder widget and it should return some cards based on the elements of a non empty list. The list is called names. I know I could use a map function but I want to use a for loop to return the cards. The code I have used so far :-
LimitedBox(
  maxHeight: 100, 
  child: List view.builder(
    itemBuilder: (BuildContext context, int v){
   for (var i = 0; i > names.length; i++){
      return Card(child: Text(names[i]),
);
}
},
),
);

What am I actually doing wrong? Any help would be great. 😊

Ralph Bergmann

unread,
Mar 31, 2020, 8:59:24 AM3/31/20
to Souvik Dutta, flutt...@googlegroups.com
Try this:

final names = <String>[];
LimitedBox(
  maxHeight: 100,
  child: ListView.builder(
    itemCount: names.length,
    itemBuilder: (BuildContext context, int i) {
      return Text(names[i]);
    },
  ),
);
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/CADRXHdJaYqDOGOv4siV_gTDkAtv1muT_qZdP--6VbP9D-ujX8Q%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages