0

How can I make a loop in a Row widget?

Here is my list:

  List childList = [
    {
      'name': 'Sofie Laurson',
      'old': '39 months',
      'image': 'images/female.jpeg'
    },
    {'name': 'John Snow', 'old': '2 years', 'image': 'images/male.jpeg'}
  ];

and here is the Row:

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: <Widget>[
    CircleAvatar(
      radius: 30.0,
      backgroundImage: AssetImage("images/female.jpeg"),
    ),
    Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text(
          'Sophie Casey',
          style: TextStyle(
            fontSize: 20.0,
          ),
        ),
        Text(
          '39 month',
          style: TextStyle(
           fontSize: 16.0, color: Colors.black45,
          ),
        ),
      ],
    ),
    Text(
      'Edit',
      style: TextStyle(color: redColor, fontSize: 18.0),
    ),
  ],
),

I need to fill the name, image path and age. Thanks!

1 Answer 1

1

Welcome to Stack Overflow.

For your problem, I would recommend a ListView.builder. It will dynamically build a list and provide you with a build method with an index so you can go through your list. It will repeat until it runs out of items in the list, providing you provide the itemCount parameter with a value.

I have made an example on DartPad to illustrate: https://dartpad.dartlang.org/d62f2a463b889e6ed40e521fbe241c8f

UPDATE: I changed the gist behind the DartPad to better match your example of a map in a list.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, great, thank you very much for help! This is working now :)
If it helped you, make sure to mark it as the accepted answer so others can see it in search results if they're facing the same issue. :)

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.