In Android we have variety of dpi drawable folders so we add background images in that based on resolution. Same like in iOS we add in 1x, 2x and 3x based on screen sizes. But how we will add multi resolution images in Flutter assets?
Ex:
Android
drawable-hdpi
- login_background.jpeg
drawable-mdpi
- login_background.jpeg
drawable-xhdpi
- login_background.jpeg
drawable-xxhdpi
- login_background.jpeg
drawable-xxxdpi
- login_background.jpeg
How we add multiple drawables in flutter to support multiple screen sizes without image stretching or scaling?
Flutter defines ratios like ios so, for example, you can create a folder named 0.75x under the assets/images for ldpi images. Other densities are as below
Dentisity Flutter pixel ratio
ldpi 0.75x
mdpi 1.0x
hdpi 1.5x
xhdpi 2.0x
xxhdpi 3.0x
xxxhdpi 4.0x
See documentation here
How Flutter handles multi-resolution images is explained here.
It comes basically down to this:
AssetImage understands how to map a logical requested asset onto one that most closely matches the current device pixel ratio. In order for this mapping to work, assets should be arranged according to a particular directory structure: (...)
An example:
.../my_icon.png .../2.0x/my_icon.png .../3.0x/my_icon.png
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