'How to store data from firestore locally on mobile?

In my app we have messaging facility which allows user to have conversation with admin. But whenever user get onto the message screen all the message documents get's loaded. Right now I am requesting all the message documents from firestore as a stream in a streambuilder which eventually make changes whenever new message arrives.

My question is - how can I store the messages as a list in the mobile so that I will only request message documents after the last loaded message on mobile and I won't request all the message documents every time. I think this will exponentially reduce the document reads from the billing.



Solution 1:[1]

you can create observable list of your message model and add every message your user send to admin then store it on the shared preferences and you can determine time for clearing database not to have all your message has added , if you wanna to have some special messages in databse and still after that delay be there you can implement sth like whatsapp and star your messages and not to delete them by filer or another. that was scenario witch came in my mind after reading your question and hope to help you I will leave some links down below about shared preference package and one video to learn how to use as you use case sorry it was to long but I had explained what I can implement links: shared_preferences: ^2.0.13 YouTube video

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Delta