I need to fetch a list of Messages using Riverpod provider, from Firestore. When I send a new message, I add the new message in Firestore, which updates the provider. But until the Firestore database has been updated, I want to add that message to the list of messages locally. How do I approach this? Please provide some example code.
p.s - I'm using riverpod code generation
It was pretty simple actually,
When adding a new item from the repository code, call
ref.read(messageByIdProvider(id).notifier).add(item). This adds the item locally, and when Firebase gets updated it gets automatically overridden becausemessagebyIdProvideris subscribed to firebase.