From 68f5e5e4dc61a73f1319e168c7eb3a0ff771efe0 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 26 Nov 2020 13:41:46 +0100 Subject: [PATCH] fix scroll to bottom button --- lib/src/message_list_view.dart | 64 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 1be1d0aa..a1b09e43 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -309,19 +309,8 @@ class _MessageListViewState extends State { return messageWidget; }, ), - if (streamChannel.channel.state.members.contains((Member e) => - e.userId == streamChannel.channel.client.state.user.id) && - widget.showScrollToBottom) - StreamBuilder( - stream: streamChannel.channel.state.unreadCountStream, - builder: (context, snapshot) { - if (!_showScrollToBottom || - !snapshot.hasData || - snapshot.data == 0) { - return SizedBox(); - } - return _buildScrollToBottom(snapshot.data); - }), + if (widget.showScrollToBottom && _showScrollToBottom) + _buildScrollToBottom(), Positioned( top: 20.0, child: ValueListenableBuilder>( @@ -364,7 +353,8 @@ class _MessageListViewState extends State { position.itemLeadingEdge > max.itemLeadingEdge ? position : max); } - Widget _buildScrollToBottom(int unreadCount) { + Widget _buildScrollToBottom() { + final streamChannel = StreamChannel.of(context); return Positioned( bottom: 8, right: 8, @@ -389,24 +379,34 @@ class _MessageListViewState extends State { ); }, ), - Positioned( - width: 20, - height: 20, - left: 10, - top: -10, - child: CircleAvatar( - child: Padding( - padding: const EdgeInsets.all(3.0), - child: Text( - unreadCount.toString(), - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.bold, - ), - ), - ), - ), - ), + if (streamChannel.channel.state.members.any((Member e) => + e.userId == streamChannel.channel.client.state.user.id)) + StreamBuilder( + stream: streamChannel.channel.state.unreadCountStream, + initialData: streamChannel.channel.state.unreadCount, + builder: (context, snapshot) { + if (!snapshot.hasData || snapshot.data <= 0) { + return Offstage(); + } + return Positioned( + width: 20, + height: 20, + left: 10, + top: -10, + child: CircleAvatar( + child: Padding( + padding: const EdgeInsets.all(3.0), + child: Text( + snapshot.data.toString(), + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ); + }), ], ), );