From 86d7017662232a11e87e7f13aac5e45cd0c61aa6 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 13 Jun 2023 16:21:19 +0530 Subject: [PATCH 1/2] fix(ui): fix scrollController not working correctly for unread. Signed-off-by: xsahil03x --- .../message_list_view/message_list_view.dart | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart index 4c29eb69..8863c991 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart @@ -852,20 +852,25 @@ class _StreamMessageListViewState extends State { streamChannel!.channel.markRead(); } - final index = unreadCount > 0 ? unreadCount + 1 : 0; - + // If the channel is not up to date, we need to reload it before scrolling + // to the end of the list. if (!_upToDate) { - _bottomPaginationActive = false; - initialAlignment = 0; + // Reset the pagination variables. initialIndex = 0; + initialAlignment = 0; + _bottomPaginationActive = false; + + // Reload the channel to get the latest messages. await streamChannel!.reloadChannel(); - WidgetsBinding.instance.addPostFrameCallback((_) { - _scrollController!.jumpTo(index: index); - }); - } else { + // Wait for the frame to be rendered with the updated channel state. + await WidgetsBinding.instance.endOfFrame; + } + + // Scroll to the end of the list. + if (_scrollController?.isAttached == true) { _scrollController!.scrollTo( - index: index, + index: 0, duration: const Duration(seconds: 1), curve: Curves.easeInOut, ); From e03a01685c64dabe0ac18d53efa24fc0229fc13a Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 13 Jun 2023 16:22:36 +0530 Subject: [PATCH 2/2] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 17cdf699..9f901bf4 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -4,6 +4,8 @@ - [[#1600]](https://github.com/GetStream/stream-chat-flutter/issues/1600) Fixed type `ImageDecoderCallback` not found error on pre-Flutter 3.10.0 versions. +- [[#1605]](https://github.com/GetStream/stream-chat-flutter/issues/1605) Fixed Null exception is thrown on message list + for unread messages when `ScrollToBottomButton` is pressed. ## 6.3.0