Not able to retrieve data from firestore

北战南征 提交于 2019-12-13 10:52:44

问题


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.

I tried this:

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

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

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

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


回答1:


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

Should try this

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

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


来源:https://stackoverflow.com/questions/56017835/not-able-to-retrieve-data-from-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!