how to check favorite item document is exist from firestore

一曲冷凌霜 提交于 2020-01-25 07:32:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!