I have a list of members List<AllMembers> _clanoviZaDijeljenje = []; and I want to iterate thorugh this list and display name of each member. I'm tryng something like this
_clanoviZaDijeljenje.map((member) { return Text(member.name);}); and i get error: The element type 'Iterable' can't be assigned to the list type 'Widget'.
-
1try this : _clanoviZaDijeljenje.map((e)=> Text(e.name)).toList();Hardik Mehta– Hardik Mehta2022-08-10 10:05:20 +00:00Commented Aug 10, 2022 at 10:05
Add a comment
|
2 Answers
Remember that .map returns Iterable<T>.
Whenever you need a list you have to cast iterable to the list by adding .toList():
_clanoviZaDijeljenje.map((member) { return Text(member.name);}).toList();
2 Comments
Ranko Koturic
So should add members to the list with map, and then to display names iterate thorugh that list?
Chris
var members = _clanoviZaDijeljenje.map((member) { return Text(member.name);}).toList(); then display the list: Column(children: members) You can omit assigning members variable and directly assign children.