use channe.state.unreacCountStream

This commit is contained in:
Salvatore Giordano
2020-10-23 16:03:03 +02:00
parent 876275aa54
commit 4a6c062484
5 changed files with 48 additions and 30 deletions
+21 -12
View File
@@ -12,17 +12,26 @@ class UnreadIndicator extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 8.0),
child: CircleAvatar(
backgroundColor:
StreamChatTheme.of(context).channelPreviewTheme.unreadCounterColor,
radius: 6,
child: Text(
'${channel.state.unreadCount}',
style: TextStyle(fontSize: 8),
),
),
);
return StreamBuilder<int>(
stream: channel.state.unreadCountStream,
initialData: channel.state.unreadCount,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == 0) {
return SizedBox();
}
return Padding(
padding: const EdgeInsets.only(left: 8.0),
child: CircleAvatar(
backgroundColor: StreamChatTheme.of(context)
.channelPreviewTheme
.unreadCounterColor,
radius: 6,
child: Text(
'${snapshot.data}',
style: TextStyle(fontSize: 8),
),
),
);
});
}
}