Skip to content

### 🖼️ Asset Management Issue: Avoid Hardcoded Asset Paths #14

@ajaxspace

Description

@ajaxspace

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:

  1. Add to pubspec.yaml:
dev_dependencies:
  flutter_gen_runner:
  build_runner:

flutter_gen:
  assets:
    enabled: true
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions