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

[FR]: Asset path as const #419

Open
2 tasks done
Nico04 opened this issue Sep 8, 2023 · 1 comment
Open
2 tasks done

[FR]: Asset path as const #419

Nico04 opened this issue Sep 8, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Nico04
Copy link

Nico04 commented Sep 8, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

I have several const that defines some static data in my app.
Before using flutter_gen, I could write something like this :
const breath = MultiSelectorItem('breath', 'assets/breath.svg', 'Breath');

But when using flutter_gen, this line doesn't work anymore :
const breath = MultiSelectorItem('breath', Assets.breath.path, 'Breath');

Describe the solution

It seems that it's because the generated class SvgGenImage.path is a getter, so NOT const.

class SvgGenImage {
  const SvgGenImage(this._assetName);

  final String _assetName;

  [...]

  String get path => _assetName;
  String get keyName => _assetName;
}

Do you have an idea how can I use the asset path in a const ?

Additional context

I now I could remove flutter_svg: true in pubspec, but using this kind of code is also handy :
child: Assets.breath.svg()

Request looks similar to #351, but it is somewhat different.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Nico04 Nico04 added the enhancement New feature or request label Sep 8, 2023
@Nico04 Nico04 changed the title [FR]: [FR]: Asset path as const Sep 8, 2023
@myxzlpltk
Copy link

Even though this looks good. If its related to data or state, I think you should separate UI and logic. Create enum instead, and use switch from that.

child: switch(enumValue) {
    SomeEnum.Type1: Assets.breath.svg(),
    ....
}

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

No branches or pull requests

2 participants