Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter firestore fetch documents with a condition on a map field

So I have a document in this form:

Field:
    NestedField: Value

How can I use the where() method in Flutter to fetch all documents that satisfy a condition on NestedField? I.e:

Firestore.collection("forms").where("Field.NestedField",isEqualsTo: "Op1").getDocuments(). // This returns null
like image 983
Amine Avatar asked Dec 08 '25 09:12

Amine


1 Answers

Alright, so this was caused by another error with no relation to Firestore directly. The Field.NesterForm approach works and it returns the data. Since Firestore uses JSON then it's the correct way to access nested fields this way. The code I was testing with was:

List<DocumentSnapshot> docs;
await Firestore.instance.collection('form')
..where("FirstForm.Operator",isEqualTo: _filter.text)
.getDocuments().then((query) {
    docs = query.documents;
});
print("DOCS: $docs");

The .. before the where() that I didn't see at first caused the awaitto not actually wait for the return so the print of my docs variable always returned null. Once I removed one dot, it works fine now and the equals is working.

like image 65
Amine Avatar answered Dec 11 '25 02:12

Amine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!