From 615a3de097734ea07370cb0187076e8cf28342f2 Mon Sep 17 00:00:00 2001 From: Nicolas Braun Date: Mon, 5 May 2025 15:32:39 +0200 Subject: [PATCH] Fix insertion in reverse chat list always at position 0 --- .../chat_animated_list/chat_animated_list_reversed.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list_reversed.dart b/packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list_reversed.dart index c4c225e1..42094407 100644 --- a/packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list_reversed.dart +++ b/packages/flutter_chat_ui/lib/src/chat_animated_list/chat_animated_list_reversed.dart @@ -163,7 +163,7 @@ class _ChatAnimatedListReversedState extends State event.message != null, 'Message must be provided when inserting a message.', ); - _onInserted(0, event.message!); + _onInserted(event.index!, event.message!); _oldList = List.from(_chatController.messages); break; case ChatOperationType.remove: @@ -570,7 +570,10 @@ class _ChatAnimatedListReversedState extends State widget.insertAnimationDuration) : widget.insertAnimationDuration; - _listKey.currentState!.insertItem(position, duration: duration); + _listKey.currentState!.insertItem( + max(_oldList.length - 1 - position, 0).toInt(), + duration: duration, + ); // Used later to trigger scroll to end only for the last inserted message. _lastInsertedMessageId = data.id;