Merge pull request #1607 from GetStream/fix/scrollcontroller-null-check

This commit is contained in:
Sahil Kumar
2023-06-13 16:40:05 +05:30
committed by GitHub
2 changed files with 16 additions and 9 deletions
@@ -4,6 +4,8 @@
- [[#1600]](https://github.com/GetStream/stream-chat-flutter/issues/1600) Fixed type `ImageDecoderCallback` not found - [[#1600]](https://github.com/GetStream/stream-chat-flutter/issues/1600) Fixed type `ImageDecoderCallback` not found
error on pre-Flutter 3.10.0 versions. 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 ## 6.3.0
@@ -852,20 +852,25 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
streamChannel!.channel.markRead(); 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) { if (!_upToDate) {
_bottomPaginationActive = false; // Reset the pagination variables.
initialAlignment = 0;
initialIndex = 0; initialIndex = 0;
initialAlignment = 0;
_bottomPaginationActive = false;
// Reload the channel to get the latest messages.
await streamChannel!.reloadChannel(); await streamChannel!.reloadChannel();
WidgetsBinding.instance.addPostFrameCallback((_) { // Wait for the frame to be rendered with the updated channel state.
_scrollController!.jumpTo(index: index); await WidgetsBinding.instance.endOfFrame;
}); }
} else {
// Scroll to the end of the list.
if (_scrollController?.isAttached == true) {
_scrollController!.scrollTo( _scrollController!.scrollTo(
index: index, index: 0,
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
curve: Curves.easeInOut, curve: Curves.easeInOut,
); );