I'm using package search_page
I want to show user name when searching their name like this example
Here is my Firestore, I have user named Test User One and Test User Two
Here is my code for FloatingActionButton( )
FloatingActionButton(
onPressed: () => showSearch(
context: context,
delegate: ChatSearch(),
),
child: Icon(Icons.chat),
),
Here is my code for ChatSearch( )
class ChatSearch extends SearchDelegate {
FirebaseFirestore _fires = FirebaseFirestore.instance;
Future<QuerySnapshot> getUserInfo() async {
return await _fires.collection("Students").where("displayName", isEqualTo: query).get();
}
...
@override
Widget buildResults(BuildContext context) {
return Column(
children: [
FutureBuilder(
future: getUserInfo(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('No user found.');
}
else if (snapshot.connectionState == ConnectionState.waiting) {
return Text('Loading ...');
}
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.docs.length,
itemBuilder: (BuildContext context, int index) {
var result = snapshot.data.docs[index];
return ListTile(
title: Text(result["displayName"]),
subtitle: Text(result["society"]),
leading: CircleAvatar(backgroundImage: NetworkImage(result["photoUrl"]),),
);
},
);
}),
],
);
}
}
How can I get the query (all user name matched with search) instead of isEqualTo? For example, when I search Test User, it will appear Test User One and Test User Two
Really appreciate if anyone can help me or provide me some direction. Thanks.