I need the texts to always be the same size regardless of the device settings.
I have tried using these codes but without success:
in the Widget Text
:
fontSize: 20 * MediaQuery.textScaleFactorOf(context)
fontSize: 20 * MediaQuery.of(context).textScaleFactor
textScaleFactor
or:
MediaQueryData = MediaQuery.of(context).copyWith(
textScaleFactor: 1.0,
)
return MediaQuery(
data: mediaQueryData,
child: MyApp()
);
but if I put small font size in the device settings, the text will be a different size than when it is set to large.
MediaQuery.textScaleFactorOf(context)
return always 1
Why?
How do I determine what the user has set?
What should I do?
Thank you
2
Answers
There are several methods to approach this. I will give you my method.
Step 1
Create a file called size_config.dart and paste the below code
Step 2
In main.dart We need to init the Size Config
How to use
Select one screen first and measure the size. For example 414 x 896 is size then
32 text size you need to acheive
32 / ( 896 / 100 ) = 3.6
textsize / ( screen_height / 100 ) = value
so we can use it as
Height case
Width case
The formula is different
size / ( screen_width / 100 ) = value
32 / ( 414 / 100 ) = 7.73
By this way you can achieve almost pixel perfect responsive design
Youtube Ref: click here
Here is my solution. This code snippet is used to automatically scale the text size based on the device’s width.
The usage is as follows