From 5f1764258ea540389d40e799b7f5c3f13e4acd3a Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Wed, 4 Mar 2020 17:51:14 +0100 Subject: [PATCH] fix messages update --- lib/src/message_widget.dart | 94 ++++++++++++++++++------------------- lib/src/stream_channel.dart | 13 +---- pubspec.yaml | 2 +- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 13dbd99e..31191d8a 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -95,55 +95,53 @@ class _MessageWidgetState extends State Widget child; - if (widget.message.type == 'deleted') { - child = _buildDeletedMessage(alignment); - } else { - var row = [ - Column( - crossAxisAlignment: - isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start, - children: [ - _buildBubble(context, isLastUser), - streamChannel.channel.config.replies - ? _buildThreadIndicator(context) - : SizedBox(), - isNextUser ? SizedBox() : _buildTimestamp(alignment), - ], - ), - isNextUser - ? Container( - width: 40, - ) - : Padding( - padding: EdgeInsets.only( - left: isMyMessage ? 8.0 : 0, - right: isMyMessage ? 0 : 8.0, - ), - child: UserAvatar(user: widget.message.user), + var row = [ + Column( + crossAxisAlignment: + isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start, + children: [ + widget.message.type == 'deleted' + ? _buildDeletedMessage(alignment) + : _buildBubble(context, isLastUser), + streamChannel.channel.config.replies + ? _buildThreadIndicator(context) + : SizedBox(), + isNextUser ? SizedBox() : _buildTimestamp(alignment), + ], + ), + isNextUser + ? Container( + width: 40, + ) + : Padding( + padding: EdgeInsets.only( + left: isMyMessage ? 8.0 : 0, + right: isMyMessage ? 0 : 8.0, ), - ]; + child: UserAvatar(user: widget.message.user), + ), + ]; - if (!isMyMessage) { - row = row.reversed.toList(); - } - - child = AnimatedContainer( - duration: Duration(milliseconds: 300), - padding: const EdgeInsets.symmetric(horizontal: 10.0), - margin: EdgeInsets.only( - top: isLastUser ? 5 : 24, - bottom: widget.nextMessage == null ? 30 : 0, - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: - isMyMessage ? MainAxisAlignment.end : MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: row, - ), - ); + if (!isMyMessage) { + row = row.reversed.toList(); } + child = AnimatedContainer( + duration: Duration(milliseconds: 300), + padding: const EdgeInsets.symmetric(horizontal: 10.0), + margin: EdgeInsets.only( + top: isLastUser ? 5 : 24, + bottom: widget.nextMessage == null ? 30 : 0, + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: + isMyMessage ? MainAxisAlignment.end : MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: row, + ), + ); + return AnimatedSwitcher( duration: Duration(milliseconds: 300), child: child, @@ -155,7 +153,7 @@ class _MessageWidgetState extends State alignment: alignment, child: Padding( padding: const EdgeInsets.symmetric( - horizontal: 54, + horizontal: 16, vertical: 14, ), child: Text( @@ -551,7 +549,9 @@ class _MessageWidgetState extends State }, ) : SizedBox(), - streamChannel.channel.config.replies + (streamChannel.channel.config.replies && + widget.message.parentId == null && + !widget.isParent) ? FlatButton( child: Padding( padding: const EdgeInsets.all(28.0), diff --git a/lib/src/stream_channel.dart b/lib/src/stream_channel.dart index 85b006b5..2943441e 100644 --- a/lib/src/stream_channel.dart +++ b/lib/src/stream_channel.dart @@ -103,22 +103,13 @@ class StreamChannelState extends State { } Future queryMembersAndWatchers() async { - String firstMemberId; - if (channel.state.members?.isNotEmpty == true) { - firstMemberId = channel.state.members.first.userId; - } - String firstWatcherId; - if (channel.state.watchers?.isNotEmpty == true) { - firstWatcherId = channel.state.watchers.first.id; - } - await widget.channel.query( membersPagination: PaginationParams( - lessThan: firstMemberId, + offset: channel.state.members?.length, limit: 100, ), watchersPagination: PaginationParams( - lessThan: firstWatcherId, + offset: channel.state.watchers?.length, limit: 100, ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 70b444e4..8bbb1e0d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: file_picker: ^1.4.3+2 image_picker: ^0.6.3+4 keyboard_visibility: ^0.5.6 - stream_chat: ^0.1.15 + stream_chat: ^0.1.16 dev_dependencies: pedantic: ^1.8.0+1