use channe.state.unreacCountStream
This commit is contained in:
@@ -304,10 +304,8 @@ class _ChannelListViewState extends State<ChannelListView>
|
||||
return StreamChannel(
|
||||
key: ValueKey<String>('CHANNEL-${channel.id}'),
|
||||
channel: channel,
|
||||
child: StreamBuilder<DateTime>(
|
||||
initialData: channel.updatedAt,
|
||||
stream: channel.updatedAtStream,
|
||||
builder: (context, snapshot) {
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
Widget child;
|
||||
if (widget.channelPreviewBuilder != null) {
|
||||
child = Stack(
|
||||
|
||||
@@ -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';
|
||||
|
||||
/// 
|
||||
/// 
|
||||
@@ -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),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user