manageChatAutoScroll method
void
manageChatAutoScroll(
{ - bool bypassHeightCheck = false,
})
Implementation
void manageChatAutoScroll({bool bypassHeightCheck = false}) {
if (!chatScrollController.hasClients || !autoScrollEnabled) return;
double newListHeight =
chatScrollController.positions.lastOrNull?.maxScrollExtent ?? 0;
if (listHeight != newListHeight || bypassHeightCheck) {
// Use postFrameCallback when bypassing height check to ensure layout is updated
if (bypassHeightCheck) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (autoScrollEnabled && chatScrollController.hasClients) {
scrollToBottomChat();
// Update listHeight after scrolling
listHeight =
chatScrollController.positions.lastOrNull?.maxScrollExtent ?? 0;
}
});
} else {
scrollToBottomChat();
listHeight = newListHeight;
}
}
}