无法从Firestore检索数据 [英] Not able to retrieve data from firestore

查看:54
本文介绍了无法从Firestore检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a collection 'posts' which has documents as uid of the particular users, under each document I have array 'posts' which contains a string 'likes' and a map 'post' which again contain a string 'userpost'.

我需要在首页中显示用户帖子"的数据作为列表.有人可以建议我对此进行查询.

I need to show data of the 'userpost' as a list in my homepage. Can someone suggest me a query for this.

我尝试过:

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

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

And in my home page under listview.builder I'm retrieving data like this:-

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

但是运行后,它在主页上没有显示任何内容,并抛出了执行:构建函数返回null.

But after running It isn't showing anything in the homepage and an execption is thrown: A build function returned null.

推荐答案

Firestore QuerySnapshot,您必须对其进行循环操作才能获取实际的文档结构图

Firestore QuerySnapshot which you have to loop over to get the actual document map

应该尝试这个

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

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

这篇关于无法从Firestore检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆