Skip to content

Commit

Permalink
Add keys to list items
Browse files Browse the repository at this point in the history
  • Loading branch information
gnowoel committed Jan 18, 2025
1 parent b661b5f commit ee3a4db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/widgets/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class ChatList extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
itemCount: chats.length,
itemBuilder: (context, index) {
return ChatItem(chat: chats[index]);
final chat = chats[index];
return ChatItem(
key: ValueKey(chat.id),
chat: chat,
);
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ class _MessageListState extends State<MessageList> {

if (message is ImageMessage) {
return ImageMessageItem(
key: ValueKey(message.id),
message: message,
);
}

return TextMessageItem(
key: ValueKey(message.id),
message: message as TextMessage,
);
},
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/user_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UserList extends StatelessWidget {
itemBuilder: (context, index) {
final user = users[index];
return UserItem(
key: ValueKey(user.id),
user: users[index],
hasKnown: _hasKnown(user),
hasSeen: _hasSeen(user),
Expand Down

0 comments on commit ee3a4db

Please sign in to comment.