-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the same TextStyle on Text and RichText renders text with different font size #14675
Comments
They shouldn't be different. Do you have an example where this happens? |
This is happening when a list of items is rendered using the This is embedded in a large(ish) app currently. I will try to extract this at some point this week. |
What is your system-wide text scale setting? iirc, Text scales with the OS text scale setting, while RichText does not. |
I do not have any explicit text scale settings. |
I have managed to knock up a quick app to demonstrate the issue but this time the items rendered with the RichText are not visible at all. Maybe I have messed up something but I honestly cannot see what it could be.
|
The RichText widgets are not visible because the RichText is defaulting to white colored text. They will match the Text if With that change, the fonts for Text and RichText look identical on my setup. |
Hmm white colored text that is rather unintuitive. Why not the same default colour as the Text? Anyway I have changed it and there is a difference on my old Android phone but on the simulator they are the same.
|
The default background is black, so we default the foreground to white. When you use MaterialApp, it changes the background to white, and sets a DefaultTextStyle to set the default color to black. Text just uses the DefaultTextStyle. RichText does not know about DefaultTextStyle -- its purpose is actually to be how Text implements DefaultTextStyle, basically. |
We have no idea what could be causing this problem. Could you try running |
Here they are as requested: |
@kostaa Ok well I see the problem: the Text widgets are setting the textScaleFactor to 1.2. This comes from the MediaQuery at the root of the widget tree, which sets the textScaleFactor to 1.19. Normally that happens because there's a system text scaling factor applied in the Android settings. Are you sure you don't have a text scale factor applied? |
@Hixie Not as far as I know (the app I am using to demonstrate this issue is attached to the sixth message from the top so you might want to double check that). I suspect this might be related to the size of the screen as I deliberately use an old Android phone with a small screen for for testing. If I run this in the emulator (I cannot remember the setup off top my head) I do not see this. |
Maybe that version of Android sets a scale factor for you? |
I thought that the whole UI layer was Flutter code. Is there a way I can check this? |
Text applies the MediaQuery scale factor, which is initialized from the Android system scale factor; RichText doesn't. They're both in Dart, though. To see if your Android is applying a scale factor, you could write a pure Java app that uses Android APIs to read the scale factor (or find one in the app store). |
@kostaa is this still an issue? |
Will check and come back to you by the end of the week. |
@zoechi - yes the problem is still there. These are the Dart/Flutter versions I am running with: The mobile I tested with is the same as mentioned in the post above. |
@kostaa thanks for the update! |
This is still an issue in Flutter 1.2 |
@Niek what exactly is it you are seeing? Is the scale factor as seen by Flutter different than the scale factor as exposed by Android? |
@Hixie I don't see the mismatched font sizes anymore. But I do think it's strange that in the following code import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Testing Text and RichText',
home: Scaffold(
appBar: AppBar(
title: Text('Testing Text and RichText'),
),
body: new DefaultTextStyle(
style: new TextStyle(
inherit: true,
fontSize: 20.0,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline,
decorationColor: Colors.red,
decorationStyle: TextDecorationStyle.dotted,
color: Colors.black),
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('This is a Text field'),
RichText(
text: TextSpan(
text: 'And this is a RichText field',
style: DefaultTextStyle.of(context).style)),
]))),
),
);
}
} |
I had the same problem, with the increased size of the text in the Android OS. In the In the If I pass |
@Niek The purpose of |
That last comment @Hixie was really helpful in determining the issues I've been having with For others that may come across this issue, It appears that most instances where someone would use |
Renaming it is part of #24722, which is my list of things we would do if they weren't so breaking. |
@kostaa Is the scale factor as seen by Flutter different than the scale factor as exposed by Android? |
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away! |
Facing the same issue. With the "solution" of @andyduke it works fine (passing textScaleFactor to RichText). |
My rich text is smaller than a text with same font size even with the
solution. This is using android. |
RichText widget is actually a raw text widget Text widget is based on (and might be renamed as such in future flutter/flutter#24722. The expected behavior is achieved by using Text.rich()
Looks like there's a scaling bug with |
Fixed the font size issue (flutter/flutter#14675)
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Maybe I am missing something but when I use the same
TextStyle
on text rendered with theRichText
the text size is smaller than when rendered with theText
. Is that intentional?The text was updated successfully, but these errors were encountered: