flutter_gen icon indicating copy to clipboard operation
flutter_gen copied to clipboard

flutter gen 1x 2x 3x support is not friendly

Open OHeroJ opened this issue 3 years ago • 2 comments

For example, I don't need 1x image, how to deal with it?

assets/
    images/
          2.0x/a.png
          3.0x/a.png
assets:
   - assets/images/

i think, flutter_gen should generate:

assets:
   - assets/images/
   - assets/images/a.png   # generated
   - ....
class $AssetsImagesGen {
  const $AssetsImagesGen();

  /// File path: assets/images/a.png
  AssetGenImage get a =>
      const AssetGenImage('assets/images/a.png'); 
}

OHeroJ avatar Apr 28 '22 07:04 OHeroJ

in this way, won't this file get very large?

ZhZhZhen avatar May 18 '22 05:05 ZhZhZhen

in this way, won't this file get very large?

just use 3x ? Not so friendly for low memory devices

OHeroJ avatar May 23 '22 08:05 OHeroJ

any update?

suli1 avatar Nov 03 '23 08:11 suli1

I'm confused what the problem is.

Flutter's Resolution aware images is what determines how the assets are imported/used. FlutterGen is just following its convention.

However, https://stackoverflow.com/a/60522464/88646 shows a workaround for flutter, where you can specify the 1.0x image, without it actually being included. Perhaps that will do what you need?

bramp avatar Nov 18 '23 19:11 bramp

I've come across an issue similar to the one mentioned before in my project when using Flutter Gen for asset generation. My assets are organized as follows:

- assets/images/2.0x/
- assets/images/3.0x/

However, during the generation process, I encounter an error. The specific issue is illustrated in the following screenshot: image

Maybe this is the support that is mentioned in this issue. I suspect this issue might be related to the parsing process. It appears that Flutter Gen attempts to create a variable starting with a number.

Flutter Version:

3.13.7

Flutter Gen Package Version:

5.3.2

ramirezsebas avatar Dec 07 '23 14:12 ramirezsebas

same issue

MrLittleWhite avatar Feb 04 '24 06:02 MrLittleWhite

The gen plugin provides no extra handling than what Flutter has already done. Resolution-aware resources are designed to be organized as primary resource + variants folders. Assets in variant folders without a primary resource will not recognized as a varianted resource. For variant assets, do not include them in the pubspec, which will help to produce valid generated code, or try excluding your variant pattern in the build configuration.

AlexV525 avatar Feb 05 '24 02:02 AlexV525