I know I should not disable any of the text and bold settings set on the device but I have a reason for it. I have disabled the text size by setting the textScaleFactor to 1 on a global level. But this does nothing to avoid the user from setting the Bold Text option that also changes the size of the text. How do I override that function also so even if the user sets it on the device there is no effect on the app? I have tried setting the fontweitgh on the text item using a TextStyle but that does also not stop the Bolding.
2 Answers
After checking Text
widget I found out that it's using boldTextOverride
from MediaQuery
to change font weight of default text style provided to it. So I guess you can override it by wrapping your MeterialApp
inside of a MediaQuery
and assigning false to boldText
and set useInheritedMediaQuery
on MaterialApp
to true
to prevent it from creating another MediaQuery
. Something like this:
return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window).copyWith(boldText: false),
child: MaterialApp(
useInheritedMediaQuery: true,
),
);

- 8,322
- 5
- 43
- 92
-
1Thanks, I also found it after looking at the code, I just added where I set the SclaeFactor – Jaco Fourie Nov 22 '21 at 08:03
-
@Amir_P I use this code but doesn't work from my side – Mohammed Nabil Nov 23 '21 at 19:15
-
1@MohammedNabil Check it again. I've used `false` instead of `true` in my answer for `useInheritedMediaQuery`. – Amir_P Nov 23 '21 at 19:41
-
@Amir_P Sorry My Mistake. – Mohammed Nabil Nov 23 '21 at 19:42
Amir_P's answer is good but, when testing it out, I found that it breaks switching between dark mode and light mode in system, as the Flutter app would only apply system brightness after killing and reopening the app on iOS rather than immediately while the app is open. Therefore, I think that rather than wrapping MaterialApp
in a MediaQuery
, the following should be done:
return MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(boldText: false),
child: child!,
),
);
The builder
property of the Material App is specifically for overriding things like this - see https://api.flutter.dev/flutter/material/MaterialApp/builder.html

- 49,934
- 160
- 51
- 83

- 88
- 7
-
2This is the best answer, simple and works! The one from @Amir_P is causing weird MediaQuery.of(context).size.height problems! – SwiftiSwift Mar 01 '23 at 06:30