From a014b6423540b77c45caa26d745edb9e33447918 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 13 Oct 2025 00:36:40 +0800 Subject: [PATCH] :bug: Fix performance issue and recycle logic issue --- lib/screens/chat/room.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/screens/chat/room.dart b/lib/screens/chat/room.dart index 169565a4..596d65f2 100644 --- a/lib/screens/chat/room.dart +++ b/lib/screens/chat/room.dart @@ -545,7 +545,9 @@ class ChatRoomScreen extends HookConsumerWidget { findChildIndexCallback: (key) { if (key is! ValueKey) return null; final messageId = key.value.substring(messageKeyPrefix.length); - final index = messageList.indexWhere((m) => m.id == messageId); + final index = messageList.indexWhere( + (m) => (m.nonce ?? m.id) == messageId, + ); // Return null for invalid indices to let SuperListView handle it properly return index >= 0 ? index : null; }, @@ -564,13 +566,13 @@ class ChatRoomScreen extends HookConsumerWidget { 3; // Use a stable animation key that doesn't change during message lifecycle - final animationKey = Key('message-anim-${message.nonce ?? message.id}'); + final key = Key('$messageKeyPrefix${message.nonce ?? message.id}'); final messageWidget = chatIdentity.when( skipError: true, data: (identity) => MessageItem( - key: Key('$messageKeyPrefix${message.nonce ?? message.id}'), + key: settings.disableAnimation ? key : null, message: message, isCurrentUser: identity?.id == message.senderId, onAction: (action) { @@ -621,7 +623,7 @@ class ChatRoomScreen extends HookConsumerWidget { return settings.disableAnimation ? messageWidget : TweenAnimationBuilder( - key: animationKey, + key: key, tween: Tween(begin: 0.0, end: 1.0), duration: Duration( milliseconds: 400 + (index % 5) * 50,