For example, 100px for web:
How to convert it to a width in flutter?
SizedBox(width: 100);
100 here in flutter is logical.
For example, 100px for web:
How to convert it to a width in flutter?
SizedBox(width: 100);
100 here in flutter is logical.
2
Answers
MediaQuery.of(context).devicePixelRatio
provides the ratio between logical and physical pixels on the device.Dividing the
pxValue
by this ratio gives a rough estimate of the logical width in Flutter.For example with iPhone 12, technical specifications res is 1170 x 2532 pixels
-> Width = 1170px
-> Height = 2532px
Then measure by Dart code run on iPhone 12:
so real px width (1170) = logical width (390.0) x device pixel ratio (3.0)
-> 100px on iPhone 12 on flutter = 100/3.0 = 33.3