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 我想在ListView.builder中显示firestore数组_Dart_Flutter - Fatal编程技术网

Dart 我想在ListView.builder中显示firestore数组

Dart 我想在ListView.builder中显示firestore数组,dart,flutter,Dart,Flutter,我在firestore中有一个名为“Names”的数组。我想在ListView.builder中显示该数组元素。我尝试了很多方法,但都做不到。我不知道如何访问快照数据 FutureBuilder( future: getList(), builder: (context, AsyncSnapshot<List<dynamic>> snapshot) { if (snapshot

我在firestore中有一个名为“Names”的数组。我想在ListView.builder中显示该数组元素。我尝试了很多方法,但都做不到。我不知道如何访问快照数据

FutureBuilder(
                future: getList(),
                builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
                if (snapshot.connectionState == ConnectionState.waiting) {
                    return CircularProgressIndicator();
                  } else {
                    return Center(
                      child: ListView.builder(
                          padding: const EdgeInsets.only(bottom: 20.0),
                          scrollDirection: Axis.vertical,
                          shrinkWrap: true,
                          itemCount: snapshot.data.length,
                          itemBuilder: (context, index) {
                            return Center(
                              child: ListTile(
                                title: Text(
                                   snapshot.data[0].data), //snapshot data should dispaly in this text field
                              ),
                            );
                          }),
                    );
                  }
                },
              ),
FutureBuilder(
future:getList(),
生成器:(上下文,异步快照){
if(snapshot.connectionState==connectionState.waiting){
返回循环ProgressIndicator();
}否则{
返回中心(
子项:ListView.builder(
填充:仅限常量边集(底部:20.0),
滚动方向:轴垂直,
收缩膜:对,
itemCount:snapshot.data.length,
itemBuilder:(上下文,索引){
返回中心(
孩子:ListTile(
标题:正文(
snapshot.data[0].data),//应在此文本字段中显示快照数据
),
);
}),
);
}
},
),
这是我的getList()方法

Future getList()异步{
var firestore=firestore.instance;
文档参考docRef=
firestore.收集(“重新记录簿”).文件(“2019-05-04”);
列表信息=新列表();
docRef.get().then((datasnapshot){
if(datasnapshot.exists){
info=datasnapshot.data['Names'].toList();
打印(“#”);
打印(信息);//此行打印[aa,aghshs,fffg,fug,ghh,fggg,ghhh]
打印(info.length);//此行打印7
}
});
退货信息;

}这似乎是因为您返回的是
列表,而不是
未来的
。下面的代码应该可以工作

Future<List<dynamic>> getList() async {
  var firestore = Firestore.instance;

  DocumentReference docRef = firestore.collection('RecodeBook').document('2019-05-04');

  return docRef.get().then((datasnapshot) {
    if (datasnapshot.exists) {
      List<dynamic> info = datasnapshot.data['Names'].toList();
      print('#');
      print(info); //this line prints [aa, aghshs, fffg, fug, ghh, fggg, ghhh]
      print(info.length); //this line prints 7
      return info;
    }
  });
}
非常感谢。getList()函数工作正常。我将文本编辑为title:Text(snapshot.data[index]),然后它就工作了。
Future<List<dynamic>> getList() async {
  var firestore = Firestore.instance;

  DocumentReference docRef = firestore.collection('RecodeBook').document('2019-05-04');

  return docRef.get().then((datasnapshot) {
    if (datasnapshot.exists) {
      List<dynamic> info = datasnapshot.data['Names'].toList();
      print('#');
      print(info); //this line prints [aa, aghshs, fffg, fug, ghh, fggg, ghhh]
      print(info.length); //this line prints 7
      return info;
    }
  });
}
title: Text(
  snapshot.data[index].data), //snapshot data should display in this text field