fix scroll to bottom button

This commit is contained in:
Salvatore Giordano
2020-11-26 13:41:46 +01:00
parent 4749466a8d
commit 68f5e5e4dc
+17 -17
View File
@@ -309,19 +309,8 @@ class _MessageListViewState extends State<MessageListView> {
return messageWidget; return messageWidget;
}, },
), ),
if (streamChannel.channel.state.members.contains((Member e) => if (widget.showScrollToBottom && _showScrollToBottom)
e.userId == streamChannel.channel.client.state.user.id) && _buildScrollToBottom(),
widget.showScrollToBottom)
StreamBuilder<int>(
stream: streamChannel.channel.state.unreadCountStream,
builder: (context, snapshot) {
if (!_showScrollToBottom ||
!snapshot.hasData ||
snapshot.data == 0) {
return SizedBox();
}
return _buildScrollToBottom(snapshot.data);
}),
Positioned( Positioned(
top: 20.0, top: 20.0,
child: ValueListenableBuilder<Iterable<ItemPosition>>( child: ValueListenableBuilder<Iterable<ItemPosition>>(
@@ -364,7 +353,8 @@ class _MessageListViewState extends State<MessageListView> {
position.itemLeadingEdge > max.itemLeadingEdge ? position : max); position.itemLeadingEdge > max.itemLeadingEdge ? position : max);
} }
Widget _buildScrollToBottom(int unreadCount) { Widget _buildScrollToBottom() {
final streamChannel = StreamChannel.of(context);
return Positioned( return Positioned(
bottom: 8, bottom: 8,
right: 8, right: 8,
@@ -389,7 +379,16 @@ class _MessageListViewState extends State<MessageListView> {
); );
}, },
), ),
Positioned( if (streamChannel.channel.state.members.any((Member e) =>
e.userId == streamChannel.channel.client.state.user.id))
StreamBuilder<int>(
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, width: 20,
height: 20, height: 20,
left: 10, left: 10,
@@ -398,7 +397,7 @@ class _MessageListViewState extends State<MessageListView> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(3.0), padding: const EdgeInsets.all(3.0),
child: Text( child: Text(
unreadCount.toString(), snapshot.data.toString(),
style: TextStyle( style: TextStyle(
fontSize: 11, fontSize: 11,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@@ -406,7 +405,8 @@ class _MessageListViewState extends State<MessageListView> {
), ),
), ),
), ),
), );
}),
], ],
), ),
); );