I have a flutter chat that displays newest messages when the user arrives at the end of the list.
This is done by setting a listener on the firestore, with a limit of 10 messages (limit (10)), and when I reach the end of the message list I increase the limit of the stream by 10.
// LISTENER QUERY MESSAGES
limitdocuments = 10;
StreamBuilder(
stream: Firestore.instance
.collection('groups')
.document(groupId)
.collection("messages")
.orderBy('sentTime', descending: true)
.limit(limitdocuments)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(themeColor)));
} else {
return ListView.builder(
itemBuilder: (context, index) {
buildItem(index, snapshot.data.documents[index],true)
},
itemCount: snapshot.data.documents.length,
reverse: true,
controller: listScrollController,
);
}
},
),
// END OF THE LIST, INCREASE THE LIMIT BY 10
if(listScrollController.position.atEdge){
if(listScrollController.position.pixels == 0){
setState(() {
limitdocuments= limitdocuments+ 10;
});
}
}
My question is, does firestore re-download all messages from the database ( including old messages ) or old ones are taken from the cache?
Thanks