0

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'.

1
  • 1
    try this : _clanoviZaDijeljenje.map((e)=> Text(e.name)).toList(); Commented Aug 10, 2022 at 10:05

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

2 Comments

So should add members to the list with map, and then to display names iterate thorugh that list?
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.
0

You can use foreach cycle.

First way:

_clanoviZaDijeljenje.forEach((member) return Text(member.name));

Second way:

for(Member member in _clanoviZaDijeljenje){ return Text(member.name);}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.