initScrollControllers method
void
initScrollControllers()
Implementation
void initScrollControllers() {
chatScrollController.addListener(() {
const double topDistanceForStatus = 200.0;
const double topDistanceForPagination = 500.0;
double currentPixels =
chatScrollController.positions.lastOrNull?.pixels ?? 0;
bool isTop = currentPixels <= topDistanceForStatus;
bool isBottom =
(chatScrollController.positions.lastOrNull?.pixels ?? 0) >=
(chatScrollController.positions.lastOrNull?.maxScrollExtent ?? 0) -
100;
bool shouldLoadConversationQueries =
currentPixels <= topDistanceForPagination;
isAtTop.value = isTop;
isAtBottom.value = isBottom;
update();
if (shouldLoadConversationQueries &&
isConversationHistoryLoaded &&
!isConversationLastPage &&
!isLoadingConversationPage &&
!isLoadingConversation.value &&
conversation.value != null) {
loadConversationMessages();
}
});
}