-
-
Notifications
You must be signed in to change notification settings - Fork 150
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]: Use static const
variables instead of getters for assets when using style: dot-delimiter
#351
Comments
Tried to modify the generated code and faced I don't think there is any workaround right now to access static variables through instances. This issue can either be closed or kept as a reminder if something change with Dart in the future. |
+1 Also would like this. |
+1 would like this. |
+1 would like this. |
any update from this issue ?! |
This is impossible in the current dart. You need to take a trade-off between DX and performance. 🥲 |
in this issue you told to put style as camel case or snack case, then static const will generated. right? my second question if you know good package or extension for asset generation please tell me. thanks |
Please show your config. The generated code should looks like this: Sorry, I'm not familiar with other packages. |
This is my yaml file: name: cookpedia environment: dependencies: dev_dependencies: flutter_gen: flutter: fonts: And The generated file like this: class $AssetsIconsGen { /// File path: assets/icons/apple.svg /// File path: assets/icons/arabic.svg /// File path: assets/icons/arrow_back.svg /// File path: assets/icons/arrow_down.svg /// File path: assets/icons/calendar.svg SO It Did Not generate statics const even i put camel case in style. i dont know why. |
@Hadeel-Masoud flutter_gen:
assets:
outputs:
style: camel-case |
Thanks it works! |
@lcdsmao Could you take a look at my case as well? But it seems there is no way to put them all below flutter_gen:
output: lib/style/res
assets:
exclude:
- assets/prompts/**/* class $AssetsIconsGen {
const $AssetsIconsGen();
/// File path: assets/icons/apple_logo.svg
String get appleLogo => 'assets/icons/apple_logo.svg';
/// List of all assets
List<String> get values => [
appleLogo,
];
}
class $AssetsImagesGen {
const $AssetsImagesGen();
/// File path: assets/images/bg-grad-black-green.png
AssetGenImage get bgGradBlackGreen =>
const AssetGenImage('assets/images/bg-grad-black-green.png');
/// List of all assets
List<AssetGenImage> get values => [
bgGradBlackGreen,
];
}
class Assets {
Assets._();
static const $AssetsIconsGen icons = $AssetsIconsGen();
static const $AssetsImagesGen images = $AssetsImagesGen();
} |
Is there an existing issue for this?
Describe the problem
When generating assets using
style: dot-delimiter
, I would like to be able to access the generated assets as constant values.I found this previous issue (#185) but I would like to keep the
dot-delimiter
style.Today, the generated code look like this:
So I cannot call it like this:
This is preventing me from creating several const Widgets.
Describe the solution
The generated code could look like this:
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: