What I noted is if user tries to scroll to the top of chat messages the _limit variable which fethes snapshots has no criteria to stop incrementing. In case user tries to scroll to top quite few times then _limit value becomes unrealistically large and defeats the purpose of loading limited number of snapshots.
I'm proposing few changes in _scrollListener() which I'm using to limit the _limit:
_scrollListener() {
if (messageListScrollController.offset >= messageListScrollController.position.maxScrollExtent &&
!messageListScrollController.position.outOfRange) {
/// Stop calling set state when no more messages are there to load
if (_limit - numMessagesLoaded < 30)
setState(() => _limit += _limitIncrement);
else
print('No more messages to load');
}
}
Additional changes include:
Defining a new variable:
int numMessagesLoaded = 0;
Hi Duy,
A quick issue, somewhat related to previous one but different scenario happening due to following lines: https://github.com/duytq94/flutter-chat-demo/blob/f58e1b421d72f2c17fdb5fc0a9d1f7bfde3021dd/lib/pages/chat_page.dart#L74
What I noted is if user tries to scroll to the top of chat messages the
_limit
variable which fethes snapshots has no criteria to stop incrementing. In case user tries to scroll to top quite few times then_limit
value becomes unrealistically large and defeats the purpose of loading limited number of snapshots.I'm proposing few changes in
_scrollListener()
which I'm using to limit the_limit
:Additional changes include:
int numMessagesLoaded = 0;
builder:
ofbuildListMessage
:Thank you, Kartik