Skip to content

Commit 33fbba1

Browse files
authored
fix: message scrolling (#7207)
1 parent cea3c69 commit 33fbba1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/animated_chat_list.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
7171
event.message != null,
7272
'Message must be provided when inserting a message.',
7373
);
74-
_onInserted(0, event.message!);
74+
_onInserted(event.index!, event.message!);
7575
_oldList = List.from(_chatController.messages);
7676
break;
7777
case ChatOperationType.remove:
@@ -208,7 +208,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
208208
if (data.id == _lastInsertedMessageId &&
209209
widget.scrollController.offset >
210210
widget.scrollController.position.minScrollExtent &&
211-
(user.id == data.author.id || !_userHasScrolled)) {
211+
(user.id == data.author.id && _userHasScrolled)) {
212212
if (widget.scrollToEndAnimationDuration == Duration.zero) {
213213
widget.scrollController
214214
.jumpTo(widget.scrollController.position.minScrollExtent);
@@ -234,7 +234,7 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
234234
if (data.id == _lastInsertedMessageId &&
235235
widget.scrollController.offset >
236236
widget.scrollController.position.minScrollExtent &&
237-
(user.id == data.author.id || !_userHasScrolled)) {
237+
(user.id == data.author.id && _userHasScrolled)) {
238238
widget.scrollController
239239
.jumpTo(widget.scrollController.position.minScrollExtent);
240240
}
@@ -311,21 +311,22 @@ class ChatAnimatedListReversedState extends State<ChatAnimatedListReversed>
311311
// If for some reason `_userHasScrolled` is true and the user is not at the
312312
// bottom of the list, set `_userHasScrolled` to false so that the scroll
313313
// animation is triggered.
314-
if (_userHasScrolled &&
314+
if (position == 0 &&
315+
_userHasScrolled &&
315316
widget.scrollController.offset >
316317
widget.scrollController.position.minScrollExtent) {
317318
_userHasScrolled = false;
318319
}
319320

320321
_listKey.currentState!.insertItem(
321-
position,
322+
0,
322323
duration: widget.insertAnimationDuration,
323324
);
324325

325326
// Used later to trigger scroll to end only for the last inserted message.
326327
_lastInsertedMessageId = data.id;
327328

328-
if (position == 0) {
329+
if (position == _oldList.length) {
329330
_scrollToEnd(data);
330331
}
331332
}

0 commit comments

Comments
 (0)