From 6c1e3adf4a3ce83bb149501ca6056754f90917dd Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 10 May 2022 10:37:02 +0200 Subject: [PATCH] fix(ui): refactor message widget bottom row --- .../lib/src/message_widget.dart | 81 +++++++++++-------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget.dart index 7acb2c12..80615a5c 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget.dart @@ -878,7 +878,7 @@ class _StreamMessageWidgetState extends State const Offstage(); } - final children = []; + final children = []; final threadParticipants = widget.message.threadParticipants?.take(2); final showThreadParticipants = threadParticipants?.isNotEmpty == true; @@ -909,56 +909,70 @@ class _StreamMessageWidgetState extends State const usernameKey = Key('username'); children.addAll([ - if (showUsername) Flexible(child: _buildUsername(usernameKey)), + if (showUsername) + WidgetSpan(child: Flexible(child: _buildUsername(usernameKey))), if (showTimeStamp) - Text( - Jiffy(widget.message.createdAt.toLocal()).jm, - style: widget.messageTheme.createdAtStyle, + WidgetSpan( + child: Text( + Jiffy(widget.message.createdAt.toLocal()).jm, + style: widget.messageTheme.createdAtStyle, + ), + ), + if (showSendingIndicator) + WidgetSpan( + child: _buildSendingIndicator(), + alignment: PlaceholderAlignment.top, ), - if (showSendingIndicator) _buildSendingIndicator(), ]); final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) && (showThreadReplyIndicator || showInChannel); - final threadIndicatorWidgets = [ + final threadIndicatorWidgets = [ if (showThreadTail) - Container( - margin: EdgeInsets.only( - bottom: context.textScaleFactor * - ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), - ), - child: CustomPaint( - size: const Size(16, 32) * context.textScaleFactor, - painter: _ThreadReplyPainter( - context: context, - color: widget.messageTheme.messageBorderColor, - reverse: widget.reverse, + WidgetSpan( + child: Container( + margin: EdgeInsets.only( + bottom: context.textScaleFactor * + ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), + ), + child: CustomPaint( + size: const Size(16, 32) * context.textScaleFactor, + painter: _ThreadReplyPainter( + context: context, + color: widget.messageTheme.messageBorderColor, + reverse: widget.reverse, + ), ), ), ), if (showInChannel || showThreadReplyIndicator) ...[ if (showThreadParticipants) - SizedBox.fromSize( - size: Size((threadParticipants!.length * 8.0) + 8, 16), - child: _buildThreadParticipantsIndicator(threadParticipants), + WidgetSpan( + child: SizedBox.fromSize( + size: Size((threadParticipants!.length * 8.0) + 8, 16), + child: _buildThreadParticipantsIndicator(threadParticipants), + ), + ), + WidgetSpan( + child: InkWell( + onTap: widget.onThreadTap != null ? onThreadTap : null, + child: Text(msg, style: widget.messageTheme.repliesStyle), ), - InkWell( - onTap: widget.onThreadTap != null ? onThreadTap : null, - child: Text(msg, style: widget.messageTheme.repliesStyle), ), ], ]; - return Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: - widget.reverse ? MainAxisAlignment.end : MainAxisAlignment.start, - children: [ - if (!widget.reverse) ...threadIndicatorWidgets, - ...children, - if (widget.reverse) ...threadIndicatorWidgets.reversed, - ].insertBetween(const SizedBox(width: 8)), + return Text.rich( + TextSpan( + children: [ + if (!widget.reverse) ...threadIndicatorWidgets, + ...children, + if (widget.reverse) ...threadIndicatorWidgets.reversed, + ].insertBetween(const WidgetSpan(child: SizedBox(width: 8))), + ), + maxLines: 1, + textAlign: widget.reverse ? TextAlign.right : TextAlign.left, ); } @@ -1247,6 +1261,7 @@ class _StreamMessageWidgetState extends State ); if (isMessageRead) { child = Row( + mainAxisSize: MainAxisSize.min, children: [ if (memberCount > 2) Text(