From c7512275cecfb834d0f0c3f5c0e97ab99984a077 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 25 May 2023 12:00:13 +0530 Subject: [PATCH 1/2] fix(ui): Fix widgetSpan getting resized twice when textScaling is enabled. Signed-off-by: xsahil03x --- .../lib/src/message_widget/bottom_row.dart | 121 +++++++++--------- .../stream_channel_list_view.dart | 38 ------ 2 files changed, 63 insertions(+), 96 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart index 8d650f5c..5ca2462a 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart @@ -153,8 +153,6 @@ class BottomRow extends StatelessWidget { } } - final children = []; - final threadParticipants = message.threadParticipants?.take(2); final showThreadParticipants = threadParticipants?.isNotEmpty == true; final replyCount = message.replyCount; @@ -183,75 +181,69 @@ class BottomRow extends StatelessWidget { const usernameKey = Key('username'); - children.addAll([ + final children = [ if (showUsername) - WidgetSpan( - child: usernameBuilder?.call(context, message) ?? - Username( - key: usernameKey, - message: message, - messageTheme: messageTheme, - ), - ), + usernameBuilder?.call(context, message) ?? + Username( + key: usernameKey, + message: message, + messageTheme: messageTheme, + ), if (showTimeStamp) - WidgetSpan( - child: Text( - Jiffy(message.createdAt.toLocal()).jm, - style: messageTheme.createdAtStyle, - ), + Text( + Jiffy(message.createdAt.toLocal()).jm, + style: messageTheme.createdAtStyle, ), if (showSendingIndicator) - WidgetSpan( - child: sendingIndicatorBuilder?.call(context, message) ?? - SendingIndicatorBuilder( - messageTheme: messageTheme, - message: message, - hasNonUrlAttachments: hasNonUrlAttachments, - streamChat: streamChat, - streamChatTheme: streamChatTheme, - ), - ), - ]); + sendingIndicatorBuilder?.call(context, message) ?? + SendingIndicatorBuilder( + messageTheme: messageTheme, + message: message, + hasNonUrlAttachments: hasNonUrlAttachments, + streamChat: streamChat, + streamChatTheme: streamChatTheme, + ), + ]; final showThreadTail = !(hasUrlAttachments || isGiphy || isOnlyEmoji) && (showThreadReplyIndicator || showInChannel); - final threadIndicatorWidgets = [ + final threadIndicatorWidgets = [ if (showThreadTail) - WidgetSpan( - child: Padding( - padding: EdgeInsets.only( - bottom: context.textScaleFactor * - ((messageTheme.repliesStyle?.fontSize ?? 1) / 2), - ), - child: CustomPaint( - size: const Size(16, 32) * context.textScaleFactor, - painter: ThreadReplyPainter( - context: context, - color: messageTheme.messageBorderColor, - reverse: reverse, + // Added builder to use the nearest context to get the right + // textScaleFactor value. + Builder( + builder: (context) { + return Padding( + padding: EdgeInsets.only( + bottom: context.textScaleFactor * + ((messageTheme.repliesStyle?.fontSize ?? 1) / 2), ), - ), - ), + child: CustomPaint( + size: const Size(16, 32) * context.textScaleFactor, + painter: ThreadReplyPainter( + context: context, + color: messageTheme.messageBorderColor, + reverse: reverse, + ), + ), + ); + }, ), if (showInChannel || showThreadReplyIndicator) ...[ if (showThreadParticipants) - WidgetSpan( - child: SizedBox.fromSize( - size: Size((threadParticipants!.length * 8.0) + 8, 16), - child: ThreadParticipants( - threadParticipants: threadParticipants, - streamChatTheme: streamChatTheme, - ), + SizedBox.fromSize( + size: Size((threadParticipants!.length * 8.0) + 8, 16), + child: ThreadParticipants( + threadParticipants: threadParticipants, + streamChatTheme: streamChatTheme, ), ), - WidgetSpan( - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - onTap: _onThreadTap, - child: Text(msg, style: messageTheme.repliesStyle), - ), + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: _onThreadTap, + child: Text(msg, style: messageTheme.repliesStyle), ), ), ], @@ -266,8 +258,21 @@ class BottomRow extends StatelessWidget { return Text.rich( TextSpan( children: [ - ...children, - ].insertBetween(const WidgetSpan(child: SizedBox(width: 8))), + ...children.insertBetween(const SizedBox(width: 8)).map((child) { + 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, textAlign: reverse ? TextAlign.right : TextAlign.left, diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_view.dart b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_view.dart index d2829ffd..bf39b98d 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_view.dart @@ -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: [ - 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), - ), - ], - ); -} From 1350851f6214f6652826ad60cd03a610d99fcddb Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 25 May 2023 12:01:48 +0530 Subject: [PATCH 2/2] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 5b909acd..0ebd05ae 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -18,6 +18,8 @@ unread indicator when `currentUser` is not present in the initial member list. - [[#1487]](https://github.com/GetStream/stream-chat-flutter/issues/1487) Use localized title for `WebOrDesktopAttachmentPickerOption` in `StreamMessageInput`. +- [[#1250]](https://github.com/GetStream/stream-chat-flutter/issues/1250) Fixed bottomRow widgetSpans getting resized + twice when `textScaling` is enabled. ✅ Added