From ed6213e9386c19091ce50a7a8cf67192a39eec1c Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 5 Jan 2021 11:19:51 +0530 Subject: [PATCH] [MessageListView] fix onQuotedMessageTap Signed-off-by: Sahil Kumar --- lib/src/message_list_view.dart | 15 +- lib/src/message_widget.dart | 309 ++++++++++++++++----------------- 2 files changed, 166 insertions(+), 158 deletions(-) diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 4ce150df..1d0d4e47 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -775,15 +775,24 @@ class _MessageListViewState extends State { bottom: index == 0 ? 30 : (isNextUser ? 2 : 7), top: 3, ), - onQuotedMessageTap: (quotedMessageId) { - if (messages.map((e) => e.id).contains(quotedMessageId)) { + onQuotedMessageTap: (quotedMessageId) async { + final scrollToIndex = () { final index = messages.indexWhere((m) => m.id == quotedMessageId); _scrollController?.scrollTo( index: index, duration: const Duration(milliseconds: 350), ); + }; + if (messages.map((e) => e.id).contains(quotedMessageId)) { + scrollToIndex(); } else { - streamChannel.loadChannelAtMessage(quotedMessageId); + streamChannel.loadChannelAtMessage(quotedMessageId).then((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (messages.map((e) => e.id).contains(quotedMessageId)) { + scrollToIndex(); + } + }); + }); } }, showInChannelIndicator: widget.parentMessage == null, diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 597a60c6..0c108681 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -287,121 +287,119 @@ class _MessageWidgetState extends State { widget.message.attachments?.any((element) => element.type == 'file') == true; - final isMyMessage = - widget.message.user.id == StreamChat.of(context).user.id; - - return Portal( - child: GestureDetector( - onLongPress: () => onLongPress(context), - child: Padding( - padding: widget.padding ?? EdgeInsets.all(8), - child: Transform( - alignment: Alignment.center, - transform: Matrix4.rotationY(widget.reverse ? pi : 0), - child: FractionallySizedBox( - alignment: Alignment.centerLeft, - widthFactor: 0.75, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Stack( - clipBehavior: Clip.none, - alignment: AlignmentDirectional.bottomStart, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - if (widget.showUserAvatar == DisplayWidget.show) - _buildUserAvatar(), - SizedBox(width: 6), - if (widget.showUserAvatar == DisplayWidget.hide) - SizedBox( - width: widget.messageTheme.avatarTheme - .constraints.maxWidth + - 8, - ), - Flexible( - child: PortalEntry( - portal: Container( - transform: - Matrix4.translationValues(-16, 2, 0), - child: _buildReactionIndicator(context), - constraints: - BoxConstraints(maxWidth: 22 * 6.0), + return Material( + type: MaterialType.transparency, + child: Portal( + child: InkWell( + onLongPress: () => onLongPress(context), + child: Padding( + padding: widget.padding ?? EdgeInsets.all(8), + child: Transform( + alignment: Alignment.center, + transform: Matrix4.rotationY(widget.reverse ? pi : 0), + child: FractionallySizedBox( + alignment: Alignment.centerLeft, + widthFactor: 0.75, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Stack( + clipBehavior: Clip.none, + alignment: AlignmentDirectional.bottomStart, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + if (widget.showUserAvatar == DisplayWidget.show) + _buildUserAvatar(), + SizedBox(width: 6), + if (widget.showUserAvatar == DisplayWidget.hide) + SizedBox( + width: widget.messageTheme.avatarTheme + .constraints.maxWidth + + 8, ), - portalAnchor: Alignment(-1.0, -1.0), - childAnchor: Alignment(1, -1.0), - child: Stack( - clipBehavior: Clip.none, - children: [ - Padding( - padding: widget.showReactions - ? EdgeInsets.only( - top: widget - .message - .reactionCounts - ?.isNotEmpty == - true - ? 18 - : 0, - ) - : EdgeInsets.zero, - child: (widget.message.isDeleted && - !isFailedState) - ? Transform( - alignment: Alignment.center, - transform: Matrix4.rotationY( - widget.reverse ? pi : 0), - child: DeletedMessage( - reverse: widget.reverse, - borderRadiusGeometry: widget - .borderRadiusGeometry, - borderSide: widget.borderSide, - shape: widget.shape, - messageTheme: - widget.messageTheme, - ), - ) - : Material( - clipBehavior: Clip.antiAlias, - shape: widget.shape ?? - RoundedRectangleBorder( - side: isOnlyEmoji - ? BorderSide.none - : widget.borderSide ?? - BorderSide( - color: Theme.of(context) - .brightness == - Brightness - .dark - ? StreamChatTheme.of( - context) - .colorTheme - .white - .withAlpha( - 24) - : StreamChatTheme.of( - context) - .colorTheme - .black - .withAlpha( - 24), - ), - borderRadius: widget - .borderRadiusGeometry ?? - BorderRadius.zero, - ), - color: _getBackgroundColor(), - child: InkWell( - onLongPress: () => - onLongPress(context), + Flexible( + child: PortalEntry( + portal: Container( + transform: + Matrix4.translationValues(-16, 2, 0), + child: _buildReactionIndicator(context), + constraints: + BoxConstraints(maxWidth: 22 * 6.0), + ), + portalAnchor: Alignment(-1.0, -1.0), + childAnchor: Alignment(1, -1.0), + child: Stack( + clipBehavior: Clip.none, + children: [ + Padding( + padding: widget.showReactions + ? EdgeInsets.only( + top: widget + .message + .reactionCounts + ?.isNotEmpty == + true + ? 18 + : 0, + ) + : EdgeInsets.zero, + child: (widget.message.isDeleted && + !isFailedState) + ? Transform( + alignment: Alignment.center, + transform: Matrix4.rotationY( + widget.reverse ? pi : 0), + child: DeletedMessage( + reverse: widget.reverse, + borderRadiusGeometry: widget + .borderRadiusGeometry, + borderSide: + widget.borderSide, + shape: widget.shape, + messageTheme: + widget.messageTheme, + ), + ) + : Card( + clipBehavior: Clip.antiAlias, + elevation: 0.0, + shape: widget.shape ?? + RoundedRectangleBorder( + side: isOnlyEmoji + ? BorderSide.none + : widget.borderSide ?? + BorderSide( + color: Theme.of(context) + .brightness == + Brightness + .dark + ? StreamChatTheme.of( + context) + .colorTheme + .white + .withAlpha( + 24) + : StreamChatTheme.of( + context) + .colorTheme + .black + .withAlpha( + 24), + ), + borderRadius: widget + .borderRadiusGeometry ?? + BorderRadius.zero, + ), + color: _getBackgroundColor(), child: Padding( padding: EdgeInsets.all( hasFiles ? 2.0 : 0.0), @@ -413,8 +411,7 @@ class _MessageWidgetState extends State { MainAxisSize.min, children: [ if (_hasQuotedMessage) - _buildQuotedMessage( - isMyMessage), + _buildQuotedMessage(), ..._parseAttachments( context), if (widget.message.text @@ -427,51 +424,51 @@ class _MessageWidgetState extends State { ), ), ), - ), - ), - if (widget.showReactionPickerIndicator) - Positioned( - right: 0, - top: -6, - child: Transform( - transform: Matrix4.rotationY( - widget.reverse ? pi : 0), - child: CustomPaint( - painter: ReactionBubblePainter( - widget.messageTheme - .reactionsBackgroundColor, - widget.messageTheme - .reactionsBorderColor, + ), + if (widget.showReactionPickerIndicator) + Positioned( + right: 0, + top: -6, + child: Transform( + transform: Matrix4.rotationY( + widget.reverse ? pi : 0), + child: CustomPaint( + painter: ReactionBubblePainter( + widget.messageTheme + .reactionsBackgroundColor, + widget.messageTheme + .reactionsBorderColor, + ), ), ), ), - ), - ], + ], + ), ), ), - ), - ], - ), - if (showBottomRow) SizedBox(height: 20.0), - ], - ), - if (showBottomRow) _buildBottomRow(leftPadding), - if (isFailedState) - Positioned( - left: widget.reverse ? -3 : null, - right: widget.reverse ? null : -9, - bottom: showBottomRow ? 20 : 0, - child: Container( - decoration: BoxDecoration( - color: Colors.white, - shape: BoxShape.circle, + ], ), - child: StreamSvgIcon.error(size: 20), - ), + if (showBottomRow) SizedBox(height: 20.0), + ], ), - ], - ), - ], + if (showBottomRow) _buildBottomRow(leftPadding), + if (isFailedState) + Positioned( + left: widget.reverse ? -3 : null, + right: widget.reverse ? null : -9, + bottom: showBottomRow ? 20 : 0, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + ), + child: StreamSvgIcon.error(size: 20), + ), + ), + ], + ), + ], + ), ), ), ), @@ -480,7 +477,9 @@ class _MessageWidgetState extends State { ); } - Widget _buildQuotedMessage(bool isMyMessage) { + Widget _buildQuotedMessage() { + final isMyMessage = + widget.message.user.id == StreamChat.of(context).user.id; return QuotedMessageWidget( onTap: () { if (widget.onQuotedMessageTap != null) {