【发布时间】:2020-05-01 17:23:12
【问题描述】:
我希望将从 firestore 获取的数据存储到一个列表中,该列表将包含来自其所有文档的数据。
我将列表定义为:
List retrievedData = List();
接下来,按下按钮时,我想打印特定集合的所有文档中的数据。所以,我这样做了:
RaisedButton(
onPressed: () async {
var collectionReferece = await Firestore.instance.collection('insults');
collectionReferece.getDocuments().then((collectionSnapshot){
retrievedData = collectionSnapshot.documents.toList();
});
print(retrievedData);
},
我在控制台中期待这个:
I/flutter (11351): [{index: 200, title: This is a test 1},{index: 100, title: This is a test 2}]
但我明白了:
I/flutter (11351): [Instance of 'DocumentSnapshot', Instance of 'DocumentSnapshot']
另外,我只想将此数据存储在列表或任何其他变量中。帮帮我。谢谢。
编辑:
我尝试使用forEach,但每次按下按钮都会不断添加。
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore