Problem:
Asset paths are hardcoded directly in the code, which is fragile and error-prone:
final String assetName = isDark
? 'assets/img/dmtools-logo-network-nodes-dark.svg'
: 'assets/img/dmtools-logo-network-nodes.svg';
Issues:
- Typos in asset paths won't be caught at compile-time
- Refactoring asset names or locations requires manual updates
- Lack of autocomplete and discoverability
Recommendation:
Use the flutter_gen package to generate strongly-typed asset accessors. This improves safety, maintainability, and developer experience.
✅ Suggested fix with flutter_gen:
final assetName = isDark
? Assets.img.dmtoolsLogoNetworkNodesDark
: Assets.img.dmtoolsLogoNetworkNodes;
Setup:
- Add to
pubspec.yaml:
dev_dependencies:
flutter_gen_runner:
build_runner:
flutter_gen:
assets:
enabled: true
- Run:
flutter pub run build_runner build
Impact:
- Compile-time safety for asset usage
- Better IDE support with autocomplete
- Easier refactoring and consistent asset access
Problem:
Asset paths are hardcoded directly in the code, which is fragile and error-prone:
Issues:
Recommendation:
Use the
flutter_genpackage to generate strongly-typed asset accessors. This improves safety, maintainability, and developer experience.✅ Suggested fix with
flutter_gen:Setup:
pubspec.yaml:Impact: