Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi Resolution background images in Flutter assets

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?

like image 887
rjkolli Avatar asked Mar 04 '19 03:03

rjkolli


2 Answers

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

like image 156
Umut ADALI Avatar answered Nov 17 '22 09:11

Umut ADALI


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
like image 44
Sven Avatar answered Nov 17 '22 08:11

Sven