I have a flutter code which allows user to search for every user speaking a specific language. I implemented a loading controlled by a ‘isLoading’ bool. The thing is, when the user searchs for a language that isn’t used by any user, the loading becomes infinite. How to display a certain widget if the research doesn’t find anything?
void onSeach() async {
setState(() {
isLoading = true;
});
await DatabaseService()
.firebaseFirestore
.collection('users')
.where('languages', arrayContains: _search.text)
.get()
.then((value) {
setState(() {
doces = value.docs;
isLoading = false;
});
});
}
2
Answers
it’s better to use
FutureBuilder
orStreamBuilder
insteadthanks for your question. I will suggest you add a Navigator.pop(context) immediately after the second setState of the call response like so: