【问题标题】:Not able to retrieve data from firestore无法从 Firestore 检索数据
【发布时间】:2019-09-24 20:02:46
【问题描述】:

我有一个集合'posts',其中包含作为特定用户的uid的文档,在每个文档下我都有一个包含字符串'likes'的数组'posts'和一个再次包含字符串'userpost'的地图'post' .

我需要在我的主页中将“用户帖子”的数据显示为列表。有人可以建议我对此进行查询。

我试过这个:

return Firestore.instance.collection('posts').where('posts', arrayContains: 'post').snapshot();

在我的主页 listview.builder 下,我正在检索这样的数据:-

Text( snapshot.data.documents[i].data['userpost'], )

但是运行后首页什么都没有显示,并抛出一个execption:A build function returned null。

【问题讨论】:

  • 为快照添加等待,将其存储在变量中并首先执行console.log以查看您是否正在获取数据。不要忘记使用 .val()

标签: firebase flutter nosql google-cloud-firestore


【解决方案1】:

Firestore QuerySnapshot,您必须循环获取实际的文档映射

应该试试这个

snapshot.data.documents.map((DocumentSnapshot doc){

if(doc.data.hasdata)){
return Text( doc.data.data['userpost'], );
}
return Text('Loading');
}).toList()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2021-08-15
    • 2021-07-09
    相关资源
    最近更新 更多