fix(ui): refactor message widget bottom row

This commit is contained in:
Salvatore Giordano
2022-05-10 10:37:02 +02:00
parent 3297d73e06
commit 6c1e3adf4a
@@ -878,7 +878,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const Offstage(); const Offstage();
} }
final children = <Widget>[]; final children = <WidgetSpan>[];
final threadParticipants = widget.message.threadParticipants?.take(2); final threadParticipants = widget.message.threadParticipants?.take(2);
final showThreadParticipants = threadParticipants?.isNotEmpty == true; final showThreadParticipants = threadParticipants?.isNotEmpty == true;
@@ -909,56 +909,70 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
const usernameKey = Key('username'); const usernameKey = Key('username');
children.addAll([ children.addAll([
if (showUsername) Flexible(child: _buildUsername(usernameKey)), if (showUsername)
WidgetSpan(child: Flexible(child: _buildUsername(usernameKey))),
if (showTimeStamp) if (showTimeStamp)
Text( WidgetSpan(
Jiffy(widget.message.createdAt.toLocal()).jm, child: Text(
style: widget.messageTheme.createdAtStyle, 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) && final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) &&
(showThreadReplyIndicator || showInChannel); (showThreadReplyIndicator || showInChannel);
final threadIndicatorWidgets = <Widget>[ final threadIndicatorWidgets = <InlineSpan>[
if (showThreadTail) if (showThreadTail)
Container( WidgetSpan(
margin: EdgeInsets.only( child: Container(
bottom: context.textScaleFactor * margin: EdgeInsets.only(
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), bottom: context.textScaleFactor *
), ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
child: CustomPaint( ),
size: const Size(16, 32) * context.textScaleFactor, child: CustomPaint(
painter: _ThreadReplyPainter( size: const Size(16, 32) * context.textScaleFactor,
context: context, painter: _ThreadReplyPainter(
color: widget.messageTheme.messageBorderColor, context: context,
reverse: widget.reverse, color: widget.messageTheme.messageBorderColor,
reverse: widget.reverse,
),
), ),
), ),
), ),
if (showInChannel || showThreadReplyIndicator) ...[ if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants) if (showThreadParticipants)
SizedBox.fromSize( WidgetSpan(
size: Size((threadParticipants!.length * 8.0) + 8, 16), child: SizedBox.fromSize(
child: _buildThreadParticipantsIndicator(threadParticipants), 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( return Text.rich(
crossAxisAlignment: CrossAxisAlignment.end, TextSpan(
mainAxisAlignment: children: [
widget.reverse ? MainAxisAlignment.end : MainAxisAlignment.start, if (!widget.reverse) ...threadIndicatorWidgets,
children: [ ...children,
if (!widget.reverse) ...threadIndicatorWidgets, if (widget.reverse) ...threadIndicatorWidgets.reversed,
...children, ].insertBetween(const WidgetSpan(child: SizedBox(width: 8))),
if (widget.reverse) ...threadIndicatorWidgets.reversed, ),
].insertBetween(const SizedBox(width: 8)), maxLines: 1,
textAlign: widget.reverse ? TextAlign.right : TextAlign.left,
); );
} }
@@ -1247,6 +1261,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
); );
if (isMessageRead) { if (isMessageRead) {
child = Row( child = Row(
mainAxisSize: MainAxisSize.min,
children: [ children: [
if (memberCount > 2) if (memberCount > 2)
Text( Text(