如何在Dart中执行foreach?
我从json输入数据,一切正常,但现在只显示第一个元素。我如何像foreach一样在这里书写,以便显示所有带有循环的元素如何在Dart中执行foreach?,dart,Dart,我从json输入数据,一切正常,但现在只显示第一个元素。我如何像foreach一样在这里书写,以便显示所有带有循环的元素 您应该使用listview builder包装数据。 尝试编写如下代码: ... else if(snapshot.hasData ){ return ListView.builder ( itemCount: snapshot.data.length, \\length of snapshot data itemBuilder: (B
您应该使用listview builder包装数据。
尝试编写如下代码:
...
else if(snapshot.hasData ){
return ListView.builder (
itemCount: snapshot.data.length, \\length of snapshot data
itemBuilder: (BuildContext ctxt, int index) {
return Container(
child:Column(
children: <Widget>[
new Padding(padding: const EdgeInsets.all(5.0)),
new Container(
child: new Text(
'Тип штрафа: ${data[index]['VDescription']}'
),
),
new Container(
child: new Text(
'Адрес: ${data[index]['VLocation']}'
),
),
new Container(
child: new Text(
'Дата: ${data[index]['VTime']}'
),
),
],
),
);
}
);
。。。
else if(snapshot.hasData){
返回ListView.builder(
itemCount:snapshot.data.length,\\快照数据的长度
itemBuilder:(BuildContext ctxt,int index){
退回货柜(
子:列(
儿童:[
新填充(填充:const EdgeInsets.all(5.0)),
新货柜(
儿童:新文本(
'аиПааафа:${data[索引]['VDescription']}'
),
),
新货柜(
儿童:新文本(
'АаС:${数据[索引]['VLocation']}'
),
),
新货柜(
儿童:新文本(
'Баааa:${data[index]['VTime']}'
),
),
],
),
);
}
);
我希望这能奏效。:)你需要清楚你想要实现什么