initScrollControllers method
void
initScrollControllers()
Implementation
void initScrollControllers() {
chatScrollController.addListener(() {
const double topDistanceForStatus = 200.0;
const double topDistanceForPagination = 500.0;
const double bottomStickinessDefault = 82.0;
const double bottomStickinessWithSendPadding = 180.0;
double currentPixels =
chatScrollController.positions.lastOrNull?.pixels ?? 0;
final double maxExtent =
chatScrollController.positions.lastOrNull?.maxScrollExtent ?? 0;
final double bottomEpsilon = chatExtraBottomPaddingActive.value
? bottomStickinessWithSendPadding
: bottomStickinessDefault;
bool isTop = currentPixels <= topDistanceForStatus;
bool isBottom = currentPixels >= maxExtent - bottomEpsilon;
bool shouldLoadConversationQueries =
currentPixels <= topDistanceForPagination;
isAtTop.value = isTop;
isAtBottom.value = isBottom;
// Re-enable auto-scroll only when the user is back at bottom and magnet is ON.
// Otherwise keep it suspended so the user can read older content.
autoScrollEnabled =
isBottom &&
autoScrollMagnetEnabled.value &&
!autoScrollSuspendedByUser;
update();
if (shouldLoadConversationQueries &&
isConversationHistoryLoaded &&
!isConversationLastPage &&
!isLoadingConversationPage &&
!isLoadingConversation.value &&
conversation.value != null) {
loadConversationMessages();
}
});
}