I got the designs for a new app. All the dimensions are Android-ready and are given in DP - (Density-independent Pixels). How can I convert these values to Flutter's LP (Logical Pixels).
I know that Window.devicePixelRatio
gives me the number of device pixels for each logical pixel.
What's the exact difference between DP and LP? Are there any built-in methods for dp to lp conversion?
According to https://api.flutter.dev/flutter/dart-ui/FlutterView/devicePixelRatio.html there are roughly 38 logical pixels per centimeter, or about 96 logical pixels per inch, of the physical display.
And according to https://developer.android.com/training/multiscreen/screendensities,One dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density screen (160dpi; the "baseline" density).
So we can say:
160 dp == 1 inch == 96 lp
According to the documentation (window.devicePixelRatio
and Flutter for Android Developers), there is no difference between DP and LP.
Device pixels are also referred to as physical pixels. Logical pixels are also referred to as device-independent or resolution-independent pixels.
Flutter doesn’t have
dp
s but there are logical pixels, which are basically the same as device-independent pixels. The so-called devicePixelRatio expresses the ratio of physical pixels in a single logical pixel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With