add channel muted ui

This commit is contained in:
Salvatore Giordano
2020-07-09 11:15:06 +02:00
parent 67dbac2857
commit a2a5b48928
2 changed files with 83 additions and 59 deletions
+82 -58
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; 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:line_awesome_icons/line_awesome_icons.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 'package:stream_chat_flutter/src/unread_indicator.dart';
@@ -42,59 +43,63 @@ class ChannelPreview extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ListTile( return Opacity(
onTap: () { opacity: channel.isMuted ? 0.5 : 1,
if (onTap != null) { child: ListTile(
onTap(channel); onTap: () {
} if (onTap != null) {
}, onTap(channel);
onLongPress: () { }
if (onLongPress != null) { },
onLongPress(channel); onLongPress: () {
} if (onLongPress != null) {
}, onLongPress(channel);
leading: ChannelImage( }
onTap: onImageTap, },
), leading: ChannelImage(
title: Row( onTap: onImageTap,
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
children: <Widget>[ title: Row(
Flexible( mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: ChannelName( children: <Widget>[
textStyle: StreamChatTheme.of(context).channelPreviewTheme.title, Flexible(
child: ChannelName(
textStyle:
StreamChatTheme.of(context).channelPreviewTheme.title,
),
), ),
), if (channel.state.unreadCount > 0)
if (channel.state.unreadCount > 0) UnreadIndicator(
UnreadIndicator( channel: channel,
channel: channel, ),
],
),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(child: _buildSubtitle(context)),
Builder(
builder: (context) {
if (channel.state.lastMessage?.user?.id ==
StreamChat.of(context).user.id) {
return Padding(
padding: const EdgeInsets.only(right: 4.0),
child: SendingIndicator(
message: channel.state.lastMessage,
allRead: channel.state.read
.where((element) => element.lastRead
.isAfter(channel.state.lastMessage.createdAt))
.length ==
channel.memberCount - 1,
),
);
}
return SizedBox();
},
), ),
], _buildDate(context),
), ],
subtitle: Row( ),
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(child: _buildSubtitle(context)),
Builder(
builder: (context) {
if (channel.state.lastMessage?.user?.id ==
StreamChat.of(context).user.id) {
return Padding(
padding: const EdgeInsets.only(right: 4.0),
child: SendingIndicator(
message: channel.state.lastMessage,
allRead: channel.state.read
.where((element) => element.lastRead
.isAfter(channel.state.lastMessage.createdAt))
.length ==
channel.memberCount - 1,
),
);
}
return SizedBox();
},
),
_buildDate(context),
],
), ),
); );
} }
@@ -129,15 +134,35 @@ class ChannelPreview extends StatelessWidget {
} }
Widget _buildSubtitle(BuildContext context) { Widget _buildSubtitle(BuildContext context) {
if (channel.isMuted) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Icon(
LineAwesomeIcons.volume_off,
size: 15,
),
Text(
'Channel is muted',
style: StreamChatTheme.of(context)
.channelPreviewTheme
.subtitle
.copyWith(
color: StreamChatTheme.of(context)
.channelPreviewTheme
.subtitle
.color,
),
),
],
);
}
return TypingIndicator( return TypingIndicator(
channel: channel, channel: channel,
alternativeWidget: _buildLastMessage(context), alternativeWidget: _buildLastMessage(context),
style: StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( style: StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith(
color: StreamChatTheme.of(context) color:
.channelPreviewTheme StreamChatTheme.of(context).channelPreviewTheme.subtitle.color,
.subtitle
.color
.withOpacity(0.5),
), ),
); );
} }
@@ -186,8 +211,7 @@ class ChannelPreview extends StatelessWidget {
color: StreamChatTheme.of(context) color: StreamChatTheme.of(context)
.channelPreviewTheme .channelPreviewTheme
.subtitle .subtitle
.color .color,
.withOpacity(0.5),
fontStyle: (lastMessage.isSystem || lastMessage.isDeleted) fontStyle: (lastMessage.isSystem || lastMessage.isDeleted)
? FontStyle.italic ? FontStyle.italic
: FontStyle.normal, : FontStyle.normal,
+1 -1
View File
@@ -231,7 +231,7 @@ class StreamChatThemeData {
), ),
subtitle: TextStyle( subtitle: TextStyle(
fontSize: 12.5, fontSize: 12.5,
color: isDark ? Colors.white : Colors.black, color: (isDark ? Colors.white : Colors.black).withOpacity(0.5),
), ),
lastMessageAt: TextStyle( lastMessageAt: TextStyle(
fontSize: 11, fontSize: 11,