Not able to retrieve data from firestore

2020-01-19 07:45发布

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条回答
▲ chillily
2楼-- · 2020-01-19 08:09

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()
查看更多
登录 后发表回答