Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate constants #185

Closed
fzyzcjy opened this issue Jan 5, 2022 · 4 comments
Closed

Generate constants #185

fzyzcjy opened this issue Jan 5, 2022 · 4 comments

Comments

@fzyzcjy
Copy link

fzyzcjy commented Jan 5, 2022

For example,

class $AssetsBlobLottieGen {
  const $AssetsBlobLottieGen();

  /// File path: assets/blob/lottie/bug.json
  String get bug => 'assets/blob/lottie/bug.json';
}

can be

class $AssetsBlobLottieGen {
  const $AssetsBlobLottieGen();

  /// File path: assets/blob/lottie/bug.json
  const bug = 'assets/blob/lottie/bug.json';
}

Similar holds for AssetGenImage and so on.

Then we can use that value as constant happily. For example,

      child: Image(
        image: Assets.icon.icon,
        width: 64,
        height: 64,
      ),

can be

      child: const Image( // <-- notice "const"
        image: Assets.icon.icon,
        width: 64,
        height: 64,
      ),
@lcdsmao
Copy link
Member

lcdsmao commented Jan 6, 2022

It is impossible to declare const field without static modifier:

Screen Shot 2022-01-06 at 9 20 25

If you want it to be const, prefer to set flutter_gen.assets.style to be either camel-case or snake-case.

flutter_gen:
  assets:
    package_parameter_enabled: false
    # Optional
    # Avaliable values:
    # - camel-case
    # - snake-case
    # - dot-delimiter
    style: dot-delimiter

Example:

static const AssetGenImage imagesChip1 =
AssetGenImage('assets/images/chip1.jpg');

@fzyzcjy
Copy link
Author

fzyzcjy commented Jan 6, 2022

Oh you are right. Thank you!

@fzyzcjy fzyzcjy closed this as completed Jan 6, 2022
@samithe7
Copy link

samithe7 commented Feb 9, 2022

 static const String imagesChip1 = 
       'assets/images/chip1.jpg'; 

how to get only String for image

@flutter-max
Copy link

hi, im using flutter_gen.assets.style as camel-case or snake-case. and same issue .
my generated file contains get, not static const

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants