FlutterGen / flutter_gen

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
https://pub.dev/packages/flutter_gen
MIT License
1.44k stars 142 forks source link

Resolution-aware image assets not generated #45

Closed SerggioC closed 3 years ago

SerggioC commented 3 years ago

Create the folders for:

Code for the assets in this folders are not generated.

Question: How does flutter gen handle images for different resolutions? This could be done automatically.

lcdsmao commented 3 years ago

Hi @SerggioC! Thanks for using FlutterGen.

Question: How does flutter gen handle images for different resolutions? This could be done automatically.

Actually, this was done automatically. If you arrange the file structure properly then those resolution-aware images will be handled properly by the flutter framework. You can check this post: https://medium.com/@nileshsenta1991/flutter-resolution-aware-image-assets-234c82216cef.

For example:

SerggioC commented 3 years ago

Hi @lcdsmao So I was defining this folders in pubspec.yaml, that is the error.

  assets:
    - assets/images/1x/
    - assets/images/2x/
    - assets/images/3x/

So we just need to put the images in the correct density folders (2.0x, 3.0x) and set pubspec:

  assets:
    - assets/images/

And the image is loaded with the correct density.

  image: Assets.brandLogo.image(),

Thanks for the help!