I am getting sick trying to adapt my app to a certain tablet dimensions using flutter.
The tablet is a Samsung Galaxy Tab S5e with screen of 2560x1600.
When I make flutter return the screen dimensions using:
print("Size W is ${MediaQuery.of(context).size.width}");
print("Size H is ${MediaQuery.of(context).size.height}");
What I get is:
Size W is 1137.7777777777778
Size H is 711.1111111111111
Then, from this answer I learned to use:
var pixRatio = MediaQuery.of(context).devicePixelRatio;
So now I can actually get the right value using:
print("Corrected size W is ${MediaQuery.of(context).size.width * pixRatio}");
print("Corrected size H is ${MediaQuery.of(context).size.height * pixRatio}");
And get:
Corrected size W is 2560.0
Corrected size H is 1600.0
The problem is that, every time I want to put a widget with dimension, Container
, Image
, specify a text size
etc on the screen, I have to use the trick like
Container(
width: 100 / pixRatio,
height: 200 / pixRatio,
),
If i do not include the /pixRatio
correction, it just draws incorrectly and I get lots of pixel overflows..
Is that the only way to put widgets on the screen with the correct size??, I mean, do I really NEED to add every single time the /pixRatio
correction on width and height??
Sounds not very practical for me.