add unread indicator

This commit is contained in:
Salvatore Giordano
2020-04-24 16:12:11 +02:00
parent 5df6c303ff
commit c3a068a4b4
4 changed files with 37 additions and 10 deletions
+3 -10
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:jiffy/jiffy.dart'; import 'package:jiffy/jiffy.dart';
import 'package:stream_chat/stream_chat.dart'; import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/unread_indicator.dart';
import '../stream_chat_flutter.dart'; import '../stream_chat_flutter.dart';
import 'channel_name.dart'; import 'channel_name.dart';
@@ -53,16 +54,8 @@ class ChannelPreview extends StatelessWidget {
children: <Widget>[ children: <Widget>[
_buildDate(context), _buildDate(context),
if (channel.state.unreadCount > 0) if (channel.state.unreadCount > 0)
Padding( UnreadIndicator(
padding: const EdgeInsets.only(left: 8.0), channel: channel,
child: CircleAvatar(
backgroundColor: Color(0xffd0021B),
radius: 6,
child: Text(
'${channel.state.unreadCount}',
style: TextStyle(fontSize: 8),
),
),
), ),
], ],
), ),
+1
View File
@@ -172,6 +172,7 @@ class StreamChatState extends State<StreamChat> with WidgetsBindingObserver {
title: themeData?.channelPreviewTheme?.title, title: themeData?.channelPreviewTheme?.title,
lastMessageAt: themeData?.channelPreviewTheme?.lastMessageAt, lastMessageAt: themeData?.channelPreviewTheme?.lastMessageAt,
subtitle: themeData?.channelPreviewTheme?.subtitle, subtitle: themeData?.channelPreviewTheme?.subtitle,
unreadCounterColor: themeData?.channelPreviewTheme?.unreadCounterColor,
), ),
); );
return theme; return theme;
+5
View File
@@ -191,6 +191,7 @@ class StreamChatThemeData {
), ),
), ),
channelPreviewTheme: ChannelPreviewTheme( channelPreviewTheme: ChannelPreviewTheme(
unreadCounterColor: Color(0xffd0021B),
avatarTheme: AvatarTheme( avatarTheme: AvatarTheme(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
constraints: BoxConstraints.tightFor( constraints: BoxConstraints.tightFor(
@@ -415,12 +416,14 @@ class ChannelPreviewTheme {
final TextStyle subtitle; final TextStyle subtitle;
final TextStyle lastMessageAt; final TextStyle lastMessageAt;
final AvatarTheme avatarTheme; final AvatarTheme avatarTheme;
final Color unreadCounterColor;
const ChannelPreviewTheme({ const ChannelPreviewTheme({
this.title, this.title,
this.subtitle, this.subtitle,
this.lastMessageAt, this.lastMessageAt,
this.avatarTheme, this.avatarTheme,
this.unreadCounterColor,
}); });
ChannelPreviewTheme copyWith({ ChannelPreviewTheme copyWith({
@@ -428,12 +431,14 @@ class ChannelPreviewTheme {
TextStyle subtitle, TextStyle subtitle,
TextStyle lastMessageAt, TextStyle lastMessageAt,
AvatarTheme avatarTheme, AvatarTheme avatarTheme,
Color unreadCounterColor,
}) => }) =>
ChannelPreviewTheme( ChannelPreviewTheme(
title: title ?? this.title, title: title ?? this.title,
subtitle: subtitle ?? this.subtitle, subtitle: subtitle ?? this.subtitle,
lastMessageAt: lastMessageAt ?? this.lastMessageAt, lastMessageAt: lastMessageAt ?? this.lastMessageAt,
avatarTheme: avatarTheme ?? this.avatarTheme, avatarTheme: avatarTheme ?? this.avatarTheme,
unreadCounterColor: unreadCounterColor ?? this.unreadCounterColor,
); );
} }
+28
View File
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
class UnreadIndicator extends StatelessWidget {
const UnreadIndicator({
Key key,
@required this.channel,
}) : super(key: key);
final Channel channel;
@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),
),
),
);
}
}