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,21 +909,29 @@ 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(
child: Text(
Jiffy(widget.message.createdAt.toLocal()).jm, Jiffy(widget.message.createdAt.toLocal()).jm,
style: widget.messageTheme.createdAtStyle, style: widget.messageTheme.createdAtStyle,
), ),
if (showSendingIndicator) _buildSendingIndicator(), ),
if (showSendingIndicator)
WidgetSpan(
child: _buildSendingIndicator(),
alignment: PlaceholderAlignment.top,
),
]); ]);
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(
child: Container(
margin: EdgeInsets.only( margin: EdgeInsets.only(
bottom: context.textScaleFactor * bottom: context.textScaleFactor *
((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2), ((widget.messageTheme.repliesStyle?.fontSize ?? 1) / 2),
@@ -937,28 +945,34 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
), ),
), ),
), ),
),
if (showInChannel || showThreadReplyIndicator) ...[ if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants) if (showThreadParticipants)
SizedBox.fromSize( WidgetSpan(
child: SizedBox.fromSize(
size: Size((threadParticipants!.length * 8.0) + 8, 16), size: Size((threadParticipants!.length * 8.0) + 8, 16),
child: _buildThreadParticipantsIndicator(threadParticipants), child: _buildThreadParticipantsIndicator(threadParticipants),
), ),
InkWell( ),
WidgetSpan(
child: InkWell(
onTap: widget.onThreadTap != null ? onThreadTap : null, onTap: widget.onThreadTap != null ? onThreadTap : null,
child: Text(msg, style: widget.messageTheme.repliesStyle), child: Text(msg, style: widget.messageTheme.repliesStyle),
), ),
),
], ],
]; ];
return Row( return Text.rich(
crossAxisAlignment: CrossAxisAlignment.end, TextSpan(
mainAxisAlignment:
widget.reverse ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [ children: [
if (!widget.reverse) ...threadIndicatorWidgets, if (!widget.reverse) ...threadIndicatorWidgets,
...children, ...children,
if (widget.reverse) ...threadIndicatorWidgets.reversed, if (widget.reverse) ...threadIndicatorWidgets.reversed,
].insertBetween(const SizedBox(width: 8)), ].insertBetween(const WidgetSpan(child: 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(