You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since Assets.vectors.homeFill is a getter, it cannot be used in a const context, limiting its usability and efficiency in compile-time constant contexts.
Describe the solution
I propose adding an option to the flutter_gen package to generate asset paths as static const variables. This would allow asset paths to be used directly in const lists, improving performance and code clarity. For example:
class Assets {
static const String homeFill = 'assets/vectors/home_fill.svg';
}
class Assets {
static class Vectors {
static const String homeFill = 'assets/vectors/home_fill.svg';
}
}
This change would enable asset paths to be utilized in const contexts, making the code more efficient and easier to maintain.
Additional context
Benefits:
Performance: static const variables are evaluated at compile-time, which can enhance performance by reducing runtime overhead.
Immutability: Using const ensures that values are fixed and immutable, adhering to Dart’s best practices.
Code Clarity: Direct access to static const values improves code readability and predictability.
Configuration: Implement this feature as an optional configuration setting in flutter_gen to let developers choose between the current getter-based approach and the proposed static const method.
Fallback: Keep the existing getter-based method for those who prefer or need the current implementation.
Thank you for considering this enhancement. It would significantly benefit developers who need to use asset paths in constant lists and improve overall code efficiency.
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the problem
I’m currently using the
flutter_gen package
for asset management in my Flutter project. The package generates asset paths using getters, like this:However, I want to use asset paths in Dart const lists, but since getters are evaluated at runtime, this isn’t possible. For instance:
Since
Assets.vectors.homeFill
is a getter, it cannot be used in a const context, limiting its usability and efficiency in compile-time constant contexts.Describe the solution
I propose adding an option to the flutter_gen package to generate asset paths as static const variables. This would allow asset paths to be used directly in const lists, improving performance and code clarity. For example:
This change would enable asset paths to be utilized in const contexts, making the code more efficient and easier to maintain.
Additional context
Benefits:
Performance: static const variables are evaluated at compile-time, which can enhance performance by reducing runtime overhead.
Immutability: Using const ensures that values are fixed and immutable, adhering to Dart’s best practices.
Code Clarity: Direct access to static const values improves code readability and predictability.
Configuration: Implement this feature as an optional configuration setting in
flutter_gen
to let developers choose between the current getter-based approach and the proposed static const method.Fallback: Keep the existing getter-based method for those who prefer or need the current implementation.
Thank you for considering this enhancement. It would significantly benefit developers who need to use asset paths in constant lists and improve overall code efficiency.
Code of Conduct
The text was updated successfully, but these errors were encountered: