mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-14 22:55:12 +10:00
fix: Improve message key handling and enhance contact tile key uniqueness
This commit is contained in:
@@ -377,6 +377,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
final reversedMessages = messages.reversed.toList();
|
||||
final itemCount =
|
||||
reversedMessages.length + (_isLoadingOlder ? 1 : 0);
|
||||
final keyedMessageIds = <String>{};
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -413,14 +414,20 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
}
|
||||
final messageIndex = index;
|
||||
final message = reversedMessages[messageIndex];
|
||||
if (!_messageKeys.containsKey(message.messageId)) {
|
||||
final shouldAttachMessageKey = keyedMessageIds.add(
|
||||
message.messageId,
|
||||
);
|
||||
if (shouldAttachMessageKey &&
|
||||
!_messageKeys.containsKey(message.messageId)) {
|
||||
_messageKeys[message.messageId] = GlobalKey();
|
||||
}
|
||||
final isUnreadAnchor =
|
||||
_unreadDividerMessageId != null &&
|
||||
message.messageId == _unreadDividerMessageId;
|
||||
return Container(
|
||||
key: _messageKeys[message.messageId]!,
|
||||
key: shouldAttachMessageKey
|
||||
? _messageKeys[message.messageId]
|
||||
: null,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
final textScale = context
|
||||
|
||||
@@ -394,7 +394,7 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
}
|
||||
|
||||
return Card(
|
||||
key: ValueKey('channel_${channel.index}'),
|
||||
key: ValueKey('${channel.index}_${channel.pskHex}_${channel.name}'),
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: GestureDetector(
|
||||
onSecondaryTapUp: PlatformInfo.isDesktop
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -827,6 +827,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
contact,
|
||||
);
|
||||
return _ContactTile(
|
||||
key: ValueKey(contact.publicKeyHex),
|
||||
contact: contact,
|
||||
lastSeen: _resolveLastSeen(contact),
|
||||
unreadCount: unreadCount,
|
||||
@@ -1495,6 +1496,7 @@ class _ContactTile extends StatelessWidget {
|
||||
final VoidCallback onLongPress;
|
||||
|
||||
const _ContactTile({
|
||||
super.key,
|
||||
required this.contact,
|
||||
required this.lastSeen,
|
||||
required this.unreadCount,
|
||||
|
||||
Reference in New Issue
Block a user