0

I have a List with this structure called userList

List userLIst = [{NAME: John, SURNAME: Doe, DATE: 24/8/2021, DESCRIPTION: Some words}, {...}, {...}];

I want to refer to that list and use List.generate(userList.length, index) => Container(display data from the list), so I can display all the data inside the cards. Is it possible to do this?

2 Answers 2

2

You should use the map method for Lists:

final widgetList = userList.map((element) => Container(child: Text(element['NAME']))).toList();

than you can display this list in a ListView or Column Widget in build method.

class YourView extends StatelessWidget{

 Widget build(){
  final widgetList = userList.map<Widget>((element) => Container(child: 
    Text(element['NAME']))).toList();

  return ListView(
    children: widgetList,
  );
 }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was looking for. Thanks!
1

Yes it's possible. you have to loop through the list generate widgets based on each map data, like this:

 for (var i in userLIst)
    Column(children:[
    Text(i.keys)
    Text(i.values),
    ])

I used for loop instead of List.generate. refer here for more information.

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.