fix(ui): Fix widgetSpan getting resized twice when textScaling is enabled.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2023-05-25 12:02:31 +05:30
committed by xsahil03x
parent d8bf365d6a
commit c7512275ce
2 changed files with 63 additions and 96 deletions
@@ -153,8 +153,6 @@ class BottomRow extends StatelessWidget {
} }
} }
final children = <WidgetSpan>[];
final threadParticipants = message.threadParticipants?.take(2); final threadParticipants = message.threadParticipants?.take(2);
final showThreadParticipants = threadParticipants?.isNotEmpty == true; final showThreadParticipants = threadParticipants?.isNotEmpty == true;
final replyCount = message.replyCount; final replyCount = message.replyCount;
@@ -183,26 +181,21 @@ class BottomRow extends StatelessWidget {
const usernameKey = Key('username'); const usernameKey = Key('username');
children.addAll([ final children = [
if (showUsername) if (showUsername)
WidgetSpan( usernameBuilder?.call(context, message) ??
child: usernameBuilder?.call(context, message) ??
Username( Username(
key: usernameKey, key: usernameKey,
message: message, message: message,
messageTheme: messageTheme, messageTheme: messageTheme,
), ),
),
if (showTimeStamp) if (showTimeStamp)
WidgetSpan( Text(
child: Text(
Jiffy(message.createdAt.toLocal()).jm, Jiffy(message.createdAt.toLocal()).jm,
style: messageTheme.createdAtStyle, style: messageTheme.createdAtStyle,
), ),
),
if (showSendingIndicator) if (showSendingIndicator)
WidgetSpan( sendingIndicatorBuilder?.call(context, message) ??
child: sendingIndicatorBuilder?.call(context, message) ??
SendingIndicatorBuilder( SendingIndicatorBuilder(
messageTheme: messageTheme, messageTheme: messageTheme,
message: message, message: message,
@@ -210,16 +203,18 @@ class BottomRow extends StatelessWidget {
streamChat: streamChat, streamChat: streamChat,
streamChatTheme: streamChatTheme, streamChatTheme: streamChatTheme,
), ),
), ];
]);
final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) && final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) &&
(showThreadReplyIndicator || showInChannel); (showThreadReplyIndicator || showInChannel);
final threadIndicatorWidgets = <WidgetSpan>[ final threadIndicatorWidgets = [
if (showThreadTail) if (showThreadTail)
WidgetSpan( // Added builder to use the nearest context to get the right
child: Padding( // textScaleFactor value.
Builder(
builder: (context) {
return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: context.textScaleFactor * bottom: context.textScaleFactor *
((messageTheme.repliesStyle?.fontSize ?? 1) / 2), ((messageTheme.repliesStyle?.fontSize ?? 1) / 2),
@@ -232,28 +227,25 @@ class BottomRow extends StatelessWidget {
reverse: reverse, reverse: reverse,
), ),
), ),
), );
},
), ),
if (showInChannel || showThreadReplyIndicator) ...[ if (showInChannel || showThreadReplyIndicator) ...[
if (showThreadParticipants) if (showThreadParticipants)
WidgetSpan( SizedBox.fromSize(
child: SizedBox.fromSize(
size: Size((threadParticipants!.length * 8.0) + 8, 16), size: Size((threadParticipants!.length * 8.0) + 8, 16),
child: ThreadParticipants( child: ThreadParticipants(
threadParticipants: threadParticipants, threadParticipants: threadParticipants,
streamChatTheme: streamChatTheme, streamChatTheme: streamChatTheme,
), ),
), ),
), MouseRegion(
WidgetSpan(
child: MouseRegion(
cursor: SystemMouseCursors.click, cursor: SystemMouseCursors.click,
child: GestureDetector( child: GestureDetector(
onTap: _onThreadTap, onTap: _onThreadTap,
child: Text(msg, style: messageTheme.repliesStyle), child: Text(msg, style: messageTheme.repliesStyle),
), ),
), ),
),
], ],
]; ];
@@ -266,8 +258,21 @@ class BottomRow extends StatelessWidget {
return Text.rich( return Text.rich(
TextSpan( TextSpan(
children: [ children: [
...children, ...children.insertBetween(const SizedBox(width: 8)).map((child) {
].insertBetween(const WidgetSpan(child: SizedBox(width: 8))), final mediaQueryData = MediaQuery.of(context);
return WidgetSpan(
child: MediaQuery(
// Hardcoding the textScaleFactor to 1 to avoid the multiple
// resizing of the text. This is needed because the
// textScaleFactor is already applied to the textSpan.
//
// issue: https://github.com/GetStream/stream-chat-flutter/issues/1250
data: mediaQueryData.copyWith(textScaleFactor: 1),
child: child,
),
);
}),
],
), ),
maxLines: 1, maxLines: 1,
textAlign: reverse ? TextAlign.right : TextAlign.left, textAlign: reverse ? TextAlign.right : TextAlign.left,
@@ -380,41 +380,3 @@ class StreamChannelListSeparator extends StatelessWidget {
); );
} }
} }
/// A widget that is used to display an error screen
/// when [StreamChannelListController] fails to load initial channels.
class StreamChannelListErrorWidget extends StatelessWidget {
/// Creates a new instance of [StreamChannelListErrorWidget] widget.
const StreamChannelListErrorWidget({
super.key,
this.onPressed,
});
/// The callback to invoke when the user taps on the retry button.
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text.rich(
TextSpan(
children: [
const WidgetSpan(
child: Padding(
padding: EdgeInsets.only(right: 2),
child: Icon(Icons.error_outline),
),
),
TextSpan(text: context.translations.loadingChannelsError),
],
),
style: Theme.of(context).textTheme.titleLarge,
),
TextButton(
onPressed: onPressed,
child: Text(context.translations.retryLabel),
),
],
);
}