用于从对象列表循环并在行中显示的颤振

问题描述 投票:0回答:1

如何在Row小部件中循环?

这是我的清单:

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

这里是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),
    ),
  ],
),

我需要填写姓名,图像路径和年龄。谢谢!

flutter dart flutter-layout
1个回答
0
投票

欢迎使用堆栈溢出。

对于您的问题,我建议您使用ListView.builder。它会动态生成一个列表,并为您提供带有索引的生成方法,以便您可以遍历列表。如果您为itemCount参数提供了一个值,它将重复执行直到列表中的项目用完为止。

我已经在DartPad上举了一个例子来说明:https://dartpad.dartlang.org/d62f2a463b889e6ed40e521fbe241c8f

更新:我更改了DartPad的主旨,以更好地匹配列表中的地图示例。

© www.soinside.com 2019 - 2024. All rights reserved.