title: bookmark / Favorite page using query firestore with flutter
body: <p>I want user to retrieve favorite by using query from firestore.</p>
  <p>My approach is to use Bool within firestore and then connect to</p>
  <pre><code>class Food {
  
    String id;
    String name;
    String category;
    String newcategory;
    String image;
    List subIngredients = [];
    Timestamp createdAt;
    Timestamp updatedAt;
    bool isFavourite;
  
    Food();
  //  Food(this.id, this.name, this.category, this.newcategory, this.image, this.subIngredients, this.createdAt, this.updatedAt);
  
    Food.fromMap(Map&lt;String, dynamic&gt; data) {
      this.id = data['id'];
      this.name = data['name'];
      this.category = data['category'];
      this.newcategory = data['newcategory'];
      this.image = data['image'];
      this.subIngredients = data['subIngredients'];
      this.createdAt = data['create at'];
      this.updatedAt = data['updatedAt'];
      this.isFavourite = data['isFavourite'];
      
    }
  
    Map&lt;String, dynamic&gt; toMap() {
      return {
        'id': this.id,
        'name': this.name,
        'category': this.category,
        'newcategory': this.newcategory,
        'image': this.image,
        'subIngredients': this.subIngredients,
        'create at': this.createdAt,
        'updatedAt': this.updatedAt,
        'isFavourite': this.isFavourite,
      };
    }
  
  }
  </code></pre>
  <p>I placed an onsaved button, but I can not figure out the proper way to have the button on product page which will save or bookmark into</p>
  <pre><code>final _saved = Set&lt;BuildContext&gt;(
      
    );
    
    @override
    Widget build(BuildContext context) {
  
        final alreadySaved =  _saved.contains(context);
  
                      new IconButton(
                      icon: alreadySaved ? Icon(Icons.star) : Icon(Icons.star_border),
                      color: alreadySaved ? Colors.yellow[500] : null,
                      onPressed:  (){
                        setState(() {
                        if (alreadySaved) {
                          _saved.remove(context);
                          } else {
                          _saved.add(context); 
                          }
                        });}
                      )
  
  </code></pre>
  <p>I started to build a query as per below in which I will include bool with if isFavorite= true</p>
  <pre><code>getFavorites(FoodNotifier foodNotifier) async {
      DocumentSnapshot querySnapshot = await Firestore.instance
          .collection('Foods')
          .document(user.uid)
          .get();
  
      if (querySnapshot.exists &amp;&amp;
          querySnapshot.data.containsKey('favorites') &amp;&amp;
          querySnapshot.data['favorites'] is List) {
        // Create a new List&lt;String&gt; from List&lt;dynamic&gt;
        return List&lt;Food&gt;.from(querySnapshot.data['favorites']);
      }
      return [];
    }
  </code></pre>
  <p>So far I am failing to create the database with bool and select per user and favorite.</p>
  <pre><code>
   final _saved = Set&lt;BuildContext&gt;(
      
    );
    
    @override
    Widget build(BuildContext context) {
  
        final alreadySaved =  _saved.contains(context);
  
      FoodNotifier foodNotifier = Provider.of&lt;FoodNotifier&gt;(context);
      
      
      _onFoodDeleted(Food food) {
        Navigator.pop(context);
        foodNotifier.deleteFood(food);
      }
  
      return Scaffold(
        appBar: AppBar(
          title: Text(foodNotifier.currentFood.name),
          actions: &lt;Widget&gt;[
                      Text('add to Favorite'),
            // action button
                      new IconButton(
                      icon: alreadySaved ? Icon(Icons.star) : Icon(Icons.star_border),
                      color: alreadySaved ? Colors.yellow[500] : null,
                      onPressed:  (){
                        setState(() {
                        if (alreadySaved) {
                          _saved.remove(context);
                          } else {
                          _saved.add(context); 
                          }
                        });}
                      )
                      ]
  </code></pre>