update sending indicator

This commit is contained in:
Salvatore Giordano
2020-06-18 11:03:28 +02:00
parent 5b5c390c82
commit 8fc314d942
5 changed files with 45 additions and 17 deletions
-1
View File
@@ -329,7 +329,6 @@ class _ChannelListViewState extends State<ChannelListView>
color: Theme.of(context).brightness == Brightness.dark
? Colors.white.withOpacity(0.1)
: Colors.black.withOpacity(0.1),
margin: EdgeInsets.symmetric(horizontal: 16),
);
}
+20 -4
View File
@@ -74,13 +74,29 @@ class ChannelPreview extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(child: _buildSubtitle(context)),
Builder(
builder: (context) {
final lastMessage = channel.state.messages.last;
if (channel.state?.messages?.isNotEmpty == true &&
lastMessage.user.id == StreamChat.of(context).user.id) {
return Padding(
padding: const EdgeInsets.only(right: 4.0),
child: SendingIndicator(
message: lastMessage,
allRead: channel.state.read
.where((element) =>
element.lastRead.isAfter(lastMessage.createdAt))
.length ==
channel.memberCount - 1,
),
);
}
return SizedBox();
},
),
_buildDate(context),
],
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[],
),
);
}
+5 -4
View File
@@ -426,10 +426,8 @@ class _MessageListViewState extends State<MessageListView> {
final isNextUser =
index - 1 >= 0 && message.user.id == messages[index - 1]?.user?.id;
final readList = StreamChannel.of(context)
.channel
.state
.read
var channel = StreamChannel.of(context).channel;
final readList = channel.state.read
.where((element) => element.user.id != userId)
.where((read) =>
read.lastRead.isAfter(message.createdAt) &&
@@ -437,6 +435,8 @@ class _MessageListViewState extends State<MessageListView> {
read.lastRead.isBefore(messages[index - 1].createdAt)))
.toList();
final allRead = readList.length == channel.memberCount - 1;
return MessageWidget(
message: message,
reverse: isMyMessage,
@@ -470,6 +470,7 @@ class _MessageListViewState extends State<MessageListView> {
? StreamChatTheme.of(context).ownMessageTheme
: StreamChatTheme.of(context).otherMessageTheme,
readList: readList,
allRead: allRead,
);
}
+12 -8
View File
@@ -91,6 +91,8 @@ class MessageWidget extends StatefulWidget {
/// If true the widget will show the reactions
final bool showReactions;
final bool allRead;
/// If true the widget will show the reply indicator
final bool showReplyIndicator;
@@ -136,6 +138,7 @@ class MessageWidget extends StatefulWidget {
this.padding,
this.textPadding = const EdgeInsets.all(8.0),
this.attachmentPadding = EdgeInsets.zero,
this.allRead = false,
}) : attachmentBuilders = {
'image': (context, message, attachment) {
return ImageAttachment(
@@ -203,9 +206,6 @@ class _MessageWidgetState extends State<MessageWidget> {
var leftPadding = widget.showUserAvatar != DisplayWidget.gone
? widget.messageTheme.avatarTheme.constraints.maxWidth + 16.0
: 6.0;
if (widget.showSendingIndicator == DisplayWidget.gone) {
leftPadding -= 7;
}
return Portal(
child: Padding(
padding: widget.padding ?? EdgeInsets.all(8),
@@ -614,11 +614,15 @@ class _MessageWidgetState extends State<MessageWidget> {
}
Widget _buildSendingIndicator() {
return Transform(
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
alignment: Alignment.center,
child: SendingIndicator(
message: widget.message,
return Padding(
padding: const EdgeInsets.only(right: 4.0),
child: Transform(
transform: Matrix4.rotationY(widget.reverse ? pi : 0),
alignment: Alignment.center,
child: SendingIndicator(
message: widget.message,
allRead: widget.allRead,
),
),
);
}
+8
View File
@@ -4,14 +4,22 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// Used to show the sending status of the message
class SendingIndicator extends StatelessWidget {
final Message message;
final bool allRead;
const SendingIndicator({
Key key,
this.message,
this.allRead = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
if (allRead) {
return Icon(
Icons.done_all,
size: 8,
);
}
if (message.status == MessageSendingStatus.SENT || message.status == null) {
return Icon(
Icons.done,