fix: Improve message key handling and enhance contact tile key uniqueness

This commit is contained in:
Winston Lowe
2026-05-11 18:19:45 -07:00
parent a270e2e6d1
commit 61c897630c
4 changed files with 18 additions and 4 deletions
+6 -1
View File
@@ -451,6 +451,7 @@ class _ChatScreenState extends State<ChatScreen> {
) {
// Reverse messages so newest appear at bottom with reverse: true
final reversedMessages = messages.reversed.toList();
var unreadAnchorKeyAssigned = false;
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
// Auto-scroll to bottom if user is already at bottom
@@ -525,7 +526,11 @@ class _ChatScreenState extends State<ChatScreen> {
children: [const UnreadDivider(), bubble],
)
: bubble;
if (identical(message, _pendingUnreadScrollTarget)) {
final shouldAttachUnreadScrollKey =
!unreadAnchorKeyAssigned &&
identical(message, _pendingUnreadScrollTarget);
if (shouldAttachUnreadScrollKey) {
unreadAnchorKeyAssigned = true;
return KeyedSubtree(key: _unreadScrollKey, child: child);
}
return child;