From 4a6c0624847a661829d50da2f007592e469c83c0 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 23 Oct 2020 16:03:03 +0200 Subject: [PATCH] use channe.state.unreacCountStream --- CHANGELOG.md | 5 +++++ lib/src/channel_list_view.dart | 6 ++---- lib/src/channel_preview.dart | 30 ++++++++++++++++++------------ lib/src/unread_indicator.dart | 33 +++++++++++++++++++++------------ pubspec.yaml | 4 ++-- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c4c6239..e51cb8bc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.11 + +- Update llc dependency +- Update widget to use `channel.state.unreadCountStream` + ## 0.2.10 - Update llc dependency diff --git a/lib/src/channel_list_view.dart b/lib/src/channel_list_view.dart index ba71e8543..f88eefbea 100644 --- a/lib/src/channel_list_view.dart +++ b/lib/src/channel_list_view.dart @@ -304,10 +304,8 @@ class _ChannelListViewState extends State return StreamChannel( key: ValueKey('CHANNEL-${channel.id}'), channel: channel, - child: StreamBuilder( - initialData: channel.updatedAt, - stream: channel.updatedAtStream, - builder: (context, snapshot) { + child: Builder( + builder: (context) { Widget child; if (widget.channelPreviewBuilder != null) { child = Stack( diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart index 5a3432aa5..95fa4a3de 100644 --- a/lib/src/channel_preview.dart +++ b/lib/src/channel_preview.dart @@ -6,7 +6,6 @@ import 'package:stream_chat_flutter/src/unread_indicator.dart'; import '../stream_chat_flutter.dart'; import 'channel_name.dart'; -import 'typing_indicator.dart'; /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/channel_preview.png) /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/screenshots/channel_preview_paint.png) @@ -103,17 +102,24 @@ class ChannelPreview extends StatelessWidget { } Widget _buildSubtitle(BuildContext context) { - final opacity = channel.state.unreadCount > 0 ? 1.0 : 0.5; - return TypingIndicator( - channel: channel, - alternativeWidget: _buildLastMessage(context, opacity), - style: StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( - color: StreamChatTheme.of(context) - .channelPreviewTheme - .subtitle - .color - .withOpacity(opacity), - ), + return StreamBuilder( + initialData: channel.state.unreadCount, + stream: channel.state.unreadCountStream, + builder: (context, snapshot) { + final opacity = (snapshot.data ?? 0) > 0 ? 1.0 : 0.5; + return TypingIndicator( + channel: channel, + alternativeWidget: _buildLastMessage(context, opacity), + style: + StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( + color: StreamChatTheme.of(context) + .channelPreviewTheme + .subtitle + .color + .withOpacity(opacity), + ), + ); + }, ); } diff --git a/lib/src/unread_indicator.dart b/lib/src/unread_indicator.dart index 73f57d05f..1b711de7e 100644 --- a/lib/src/unread_indicator.dart +++ b/lib/src/unread_indicator.dart @@ -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( + 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), + ), + ), + ); + }); } } diff --git a/pubspec.yaml b/pubspec.yaml index f2deb2f86..56d2270d1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_flutter homepage: https://github.com/GetStream/stream-chat-flutter description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter. -version: 0.2.10 +version: 0.2.11 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -23,7 +23,7 @@ dependencies: file_picker: ^2.0.0 image_picker: ^0.6.7+2 flutter_keyboard_visibility: ^3.2.1 - stream_chat: ^0.2.8 + stream_chat: ^0.2.10 mime: ^0.9.6+3 visibility_detector: ^0.1.5 http_parser: ^3.1.4