Why my widget isn't rebuilding when I update a map on Firestore?

Viewed 100

I'm trying to create a very Instagram alike interface with a like button and a like count. I'm saving my Map and managing the state of my app through Provider

In my firestore database I have a map such as collection(comidas)document(likes){meat:0,veggies:1,cheese:3}

In my flutter code I have my code that in a very simplified way goes like this

StreamBuilder(stream:firestore,builder:if(snapshot.hasData)
{Map<dynamic, dynamic> likes = snapshot.data['likes'];
//send likes to my Provider class
return ListView.builder(
          itemCount: Provider.of<Carro>(context,listen: true).menues.length,
          itemBuilder: (context, position) {
            return Tarjeta(
              comida: Provider.of<Carro>(context, listen: true).menues[position],
            );
          });
    } 
})

And in Tarjeta there's a likes counter but it is this counter the one that doesn't gets updated when the like count changes or when the user hits the like button, although if you use any other of the actions that make the widget rebuild it gets updated with the correct value. I was looking for an explanation and the only thing that may explain this that i've found is the way map indexes work on firestore. Things that I have tried :

  1. Using setState as a patch, but somehow it doesn't work.
  2. Changing the map size by adding and deleting elements to trigger the index of firestore.

And frankly I have no idea where else to look for. Any help would be greatly apreciated

TLDR: I save a Map from firestore to a Map on my Provider on flutter. When I hit the like button updating the map on firestore the widget doesnt rebuild itself

0 Answers
Related