diff --git a/lib/src/back_button.dart b/lib/src/back_button.dart index 52adeade..9d787517 100644 --- a/lib/src/back_button.dart +++ b/lib/src/back_button.dart @@ -9,11 +9,15 @@ class StreamBackButton extends StatelessWidget { Key key, this.onPressed, this.showUnreads = false, + this.cid, }) : super(key: key); final VoidCallback onPressed; final bool showUnreads; + /// Channel cid used to retrieve unread count + final String cid; + @override Widget build(BuildContext context) { return Stack( @@ -45,7 +49,9 @@ class StreamBackButton extends StatelessWidget { Positioned( top: 7, right: 7, - child: UnreadIndicator(), + child: UnreadIndicator( + cid: cid, + ), ), ], ); diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index bea2ad0b..cda0d64c 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -187,7 +187,6 @@ class MessageListView extends StatefulWidget { class _MessageListViewState extends State { ItemScrollController _scrollController; - bool _bottomWasVisible = false; Function _onThreadTap; bool _showScrollToBottom = false; ItemPositionsListener _itemPositionListener; @@ -692,14 +691,13 @@ class _MessageListViewState extends State { key: ValueKey('BOTTOM-MESSAGE'), onVisibilityChanged: (visibility) { final isVisible = visibility.visibleBounds != Rect.zero; - if (isVisible && !_bottomWasVisible) { + if (isVisible) { final channel = streamChannel.channel; if (_upToDate && channel.config?.readEvents == true && channel.state.unreadCount > 0) { streamChannel.channel.markRead(); } - _bottomWasVisible = !isVisible; } if (mounted) { setState(() => _showScrollToBottom = !isVisible); diff --git a/lib/src/thread_header.dart b/lib/src/thread_header.dart index 8e165af7..eb748272 100644 --- a/lib/src/thread_header.dart +++ b/lib/src/thread_header.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat_flutter/src/stream_chat_theme.dart'; +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'back_button.dart'; import 'channel_name.dart'; @@ -81,6 +82,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget { elevation: 1, leading: showBackButton ? StreamBackButton( + cid: StreamChannel.of(context).channel.cid, onPressed: onBackPressed, showUnreads: true, ) diff --git a/lib/src/unread_indicator.dart b/lib/src/unread_indicator.dart index c9f42fad..cf115f3b 100644 --- a/lib/src/unread_indicator.dart +++ b/lib/src/unread_indicator.dart @@ -5,14 +5,22 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'; class UnreadIndicator extends StatelessWidget { const UnreadIndicator({ Key key, + this.cid, }) : super(key: key); + /// Channel cid used to retrieve unread count + final String cid; + @override Widget build(BuildContext context) { final client = StreamChat.of(context).client; return StreamBuilder( - stream: client.state.totalUnreadCountStream, - initialData: client.state.totalUnreadCount, + stream: cid != null + ? client.state.channels[cid].state.unreadCountStream + : client.state.totalUnreadCountStream, + initialData: cid != null + ? client.state.channels[cid].state.unreadCount + : client.state.totalUnreadCount, builder: (context, snapshot) { if (!snapshot.hasData || snapshot.data == 0) { return SizedBox();