Maikzen
Maikzen

Reputation: 1624

How to make it affect device font size to RichText and TextSpan

I have a problem with RichText and TextSpan widgets. All Text widgets are affected by device font size (changed in settings) but RichText not. Any ideas about to solve it?

Upvotes: 4

Views: 1115

Answers (4)

aytunch
aytunch

Reputation: 1434

Starting with Flutter 3.x, you should set this in RichText in order for it to react to device text scale factor changes:

textScaler: MediaQuery.textScalerOf(context),

Also, on iOS Simulator, when simulator is focused, you can use shortcut keys: Command + option + plus/minus to test different text sizes

Upvotes: 1

Loren.A
Loren.A

Reputation: 5575

The accepted answer is now deprecated. This is the updated way to ensure scaling on a RichText widget. Although Text.rich() from WSBT's answer is also a great solution.

RichText(
  textScaler: TextScaler.linear(
    MediaQuery.of(context).textScaler.scale(1),
 ),

Upvotes: 1

WSBT
WSBT

Reputation: 36323

Actually RichText is one of the lower level widgets that you need to handle many things yourself.

You should try to use Text.rich() instead. It's pretty much the same thing as RichText but inherits styles from the parent widget tree.

Upvotes: 5

Maikzen
Maikzen

Reputation: 1624

I have solved it this way:

RichText(
    textScaleFactor: MediaQuery.of(context).textScaleFactor, <--- add this
    text: ...
)

Upvotes: 8

Related Questions