andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
76 stars 48 forks source link

Text.rich textScaleFactor scales twice as much #83

Closed nt4f04uNd closed 3 months ago

nt4f04uNd commented 3 months ago

textScaleFactor property comes from MediaQuery, when users change system font scaling in their OS.

When using a Text.rich with WidgetSpan with StyledText as a child, the textScaleFactor scales the text twice as much, unless we explicitly specify textScaleFactor = 1.0 on either of them

textScaleFactor=1.0

image

textScaleFactor=1.3

image

Code sample

                const Text.rich(
                  WidgetSpan(
                    child: StyledText(
                      textScaleFactor: 1.0,
                      text: 'Test: some <b>bold</b> text.',
                      tags: {
                        'b': StyledTextTag(
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                      },
                    ),
                  ),
                ),

                const Text.rich(
                  WidgetSpan(
                    child: StyledText(
                      text: 'Test: some <b>bold</b> text. (double scaling!)',
                      tags: {
                        'b': StyledTextTag(
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                      },
                    ),
                  ),
                ),
andyduke commented 3 months ago

Does this issue occur in version 8.1.0 or 9.0.0-beta-4?

andyduke commented 3 months ago

This is a problem on the Flutter side. It appears with nested RichText (StyledText uses RichText inside), see #126962.

I can advise not to use StyledText inside WidgetSpan, but to lay out everything using StyledText.