The assets_gen package provides a builder to generate a .dart file that contains all assets according to `pubspec.yaml`.
assets_gen package provides a builder to generate a .dart file that contains all assets according to
|Way to reference asset path||Sample Code|
|Use string path directly||❌ Unsafe|
|Use ||✅ Good|
Getting Started #
dev_dependencies: build_runner: ">=1.0.0 < 2.0.0" assets_gen: ">=0.2.0 <1.0.0"
flutter pub run build_runner build: Run a single build and exit.
flutter pub run build_runner watch: Continuously run builds as you edit files.
More info about build_runner.
Here are two ways to custom the generated file:
# Specify an assets_gen section in pubspec.yaml flutter: assets: - path/to/asset assets_gen: - ...
|String||Output position, always under |
|String||The generated class name.|
|bool||Whether the builder should generate extra const variable with package info, e.g. |
|bool||Whether the builder should ignore resolution variant. e.g. |
|int||The path levels of generated key that the builder will omit. e.g. if levels is 2, the key of |
|List||none||Listed assets in exclude will be ignored in generated class. It supports glob syntax.|