Reputation: 2148
I do a query to get a document by checking a Map key from firestore. I use a StreamBuilder for that. Both Id are the same in firestore and in flutter code. Do you have an idea why the snapshot is empty ? postSnapshot.data.documents.length is equal to 0, it returns [].
StreamBuilder(
stream: Firestore.instance
.collection('posts')
.orderBy('createdAt', descending: true)
.where('userlist.' + widget.user.uid, isEqualTo: true)
.snapshots(),
builder: (context, postSnapshot) {
if (postSnapshot.connectionState == ConnectionState.waiting) {
return _displaysLoading();
}
if (postSnapshot.hasData) {
...
}
}
)
Upvotes: 0
Views: 525
Reputation: 317372
Your query is returning no documents. That's because your data doesn't have a boolean true
as the value of the map. It has "user1". A query using isEqualTo: true
will never match true
to the string value you show here.
You will either need to make your query match the data and pass "user1", or make your data match the query by making the value a boolean true
.
Upvotes: 1
Reputation: 3130
try this
StreamBuilder(
stream: Firestore.instance
.collection('posts')
.orderBy('createdAt', descending: true)
.where('userlist', arrayContains: widget.user.uid)
.snapshots(),
builder: (context, postSnapshot) {
if (postSnapshot.connectionState == ConnectionState.waiting) {
return _displaysLoading();
}
if (postSnapshot.hasData) {
...
}
}
)
Upvotes: 0