Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Dart中执行foreach?_Dart - Fatal编程技术网

如何在Dart中执行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

我从json输入数据,一切正常,但现在只显示第一个元素。我如何像foreach一样在这里书写,以便显示所有带有循环的元素


您应该使用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']}'
),
),
],
),
);
}
);

我希望这能奏效。:)

你需要清楚你想要实现什么