问题
I need when user open the meal page see if that meal in favorite or not by making the favorite icon color to red but i can't check if the meal document is in firestore or not.
I've tried to put this code in init state but it doesn't work i check icon color from isFavorite boolean.
firestore
.collection('favorites')
.where('mealId', isEqualTo: widget.mealId)
.where('userId', isEqualTo: userID)
.getDocuments().then((f) {
if(f.documents.isNotEmpty) {
setState(() {
isFavorite = true;
});
} else {
setState(() {
isFavorite = false;
});
}
});
this code make all of meals have a red favorite icon.
来源:https://stackoverflow.com/questions/56736122/how-to-check-favorite-item-document-is-exist-from-firestore