如何在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),
),
],
),
我需要填写姓名,图像路径和年龄。谢谢!
欢迎使用堆栈溢出。
对于您的问题,我建议您使用ListView.builder
。它会动态生成一个列表,并为您提供带有索引的生成方法,以便您可以遍历列表。如果您为itemCount
参数提供了一个值,它将重复执行直到列表中的项目用完为止。
我已经在DartPad上举了一个例子来说明:https://dartpad.dartlang.org/d62f2a463b889e6ed40e521fbe241c8f
更新:我更改了DartPad的主旨,以更好地匹配列表中的地图示例。