Reputation: 1624
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: 1169
Reputation: 1444
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
Reputation: 5595
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
Reputation: 36383
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
Reputation: 1624
I have solved it this way:
RichText(
textScaleFactor: MediaQuery.of(context).textScaleFactor, <--- add this
text: ...
)
Upvotes: 8