I am looking to add a simple search field, would like to use something like
collectionRef.where(\'name\', \'contains\', \'searchTerm\')
I tried
This worked for me perfectly but might cause performance issues.
Do this when querying firestore:
Future searchResults = collectionRef
.where('property', isGreaterThanOrEqualTo: searchQuery.toUpperCase())
.getDocuments();
Do this in your FutureBuilder:
return FutureBuilder(
future: searchResults,
builder: (context, snapshot) {
List searchResults = [];
snapshot.data.documents.forEach((doc) {
Model model = Model.fromDocumet(doc);
if (searchQuery.isNotEmpty &&
!model.property.toLowerCase().contains(searchQuery.toLowerCase())) {
return;
}
searchResults.add(model);
})
};