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
Larger Text setting scale the app font size in iOS #22480
Comments
@ParkinWu I had same issue.The problem is the textScaleFactor :
Solution is to use builder inside materialApp and make a new MediaQuery object with fixed textScaleFactor :
Happy coding 👍 |
I would strongly recommend not disabling the textScaleFactor for the entire application, as it will severely degrade the user experience. For example, I have my textScaleFactor turned up to a modest 1.25 so that I can read my phone without glasses. |
If a particular piece of text cannot be made bigger, it would be better to set the textScaleFactor on the |
@jonahwilliams I've had same issue I was getting a lot of bug reports that text is too large or too small and etc. and changing textScaleFactor just for Text didn't work for me because there were other components that were affected with system font settings.I agree with you disabling is not good practice but if you a large codebase and short deadlines it's most effective way.For other projects I made class FixedScaleText which extends Text and sets textScaleFactor to default value 1.0. |
@harisk92 work like a charm, thank you very much! @jonahwilliams thanks for your reply, my app is a hybrid app with a large native code base,not support changing font size yet, font size changing only in some page seems strangly, ,my problem have been solved. the issue should be closed ☺ |
@harisk92 that's work for me too , thank you . |
How would you use: In the following: |
yes I used in Materialapp in first like this :-
|
You can set a limit after which you don't need to scale, as some apple apps do. MaterialApp(
builder: (BuildContext context, Widget child) {
final MediaQueryData data = MediaQuery.of(context);
return MediaQuery(
data: data.copyWith(
textScaleFactor: data.textScaleFactor > 2.0 ? 2.0 : data.textScaleFactor),
child: child,
);
},
debugShowCheckedModeBanner: false,
title: 'Flutter app',
) In addition, I added 2 functions that calculate the size for different cases.
double getFixedSize(double textSize) {
return textScaleFactor != 1.0 ? textSize / textScaleFactor : textSize;
} For example, you can use it for app title text.
double getScaledOrMaxSize(double textSize, double maxScaleFactor) {
return textScaleFactor > maxScaleFactor
? textSize * maxScaleFactor / textScaleFactor
: textSize;
} This can be used for example for headers that are already large and you don't need to increase them even more. I hope this helps you make good apps for visually impaired people while still leaving them beautiful. Please rate it on StackOverflow https://stackoverflow.com/questions/56034572/how-to-manage-global-textscalefactor-in-flutter-app-properly/61893650#61893650 |
You can easily just clamp the text scale factor to a good range for your app. builder: (context, child) {
final mediaQueryData = MediaQuery.of(context);
final scale = mediaQueryData.textScaleFactor.clamp(0.8, 1.35);
return MediaQuery(
child: child,
data: MediaQuery.of(context).copyWith(textScaleFactor: scale),
);
}, |
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 |
Hi
In Settings -> General -> Accessibility -> Larger Text, we found the setting will scale the flutter page's font size,it is a great feature, but some layout in my app need fixed font size, so is there some properties or configs that i can disable it?
@kangwang1988
thanks
The text was updated successfully, but these errors were encountered: