I have successfully filter the search results based on one field from the firestore database, what i'm trying to do now is to filter based on several fields from the firebase instead of one.
The code i presented is the entire Streambuilder with one value filter function, i hope someone can teach me how to filter multiple value based on my code, thanks in advance
TextField(
controller: searchController,
onChanged: (value) {
setState(() {
searchText = value;
});
},
decoration: InputDecoration(
hintText: 'Search...',
prefixIcon: Icon(Icons.search),
),
),
StreamBuilder(
stream: allNoteCollection.snapshots(),
builder: (ctx, streamSnapshot) {
if (streamSnapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator());
}
documents = streamSnapshot.data!.docs;
if (searchText.length > 0) {
documents = documents.where((element)
{
return element
.get('serviceName')
.toString()
.toLowerCase()
.contains(searchText.toLowerCase());
}).toList();
}
return ListView.separated(
reverse: true,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: documents.length,
separatorBuilder: (BuildContext context, int index) {
return Divider();
},
itemBuilder: (BuildContext context, int index) {
return ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 0.0),
onTap: () {
},
title: Text(documents[index]['serviceName']),
subtitle: Text(documents[index]['serviceDetails']),
);
},
);
},
),