fix: improve chat auto-scroll logic, reduce socket timeout, and prevent duplicate message sends

This commit is contained in:
pradeepkumar
2026-03-28 18:50:25 +05:30
parent 130583c98c
commit d9399a7be3
3 changed files with 34 additions and 13 deletions

View File

@@ -360,10 +360,15 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
orElse: () => null,
);
// Auto-scroll only when a NEW message is added (not on any rebuild)
if (messages.length > _previousMessageCount && _previousMessageCount > 0) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToBottom(animated: true);
});
// Only scroll if user is near the bottom (not scrolled up reading history)
if (_scrollController.hasClients &&
_scrollController.position.pixels < 150) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _scrollToBottom(animated: true);
});
}
}
_previousMessageCount = messages.length;