assets_gen 1.1.1
assets_gen: ^1.1.1 copied to clipboard

The assets_gen package helps you to generate a .dart file that contains all assets according to `pubspec.yaml`.

assets_gen #

Pub Version

The assets_gen package helps you to generate a .dart file that contains all assets according to pubspec.yaml.

Way to reference asset pathSample Code
Use string path directlyImage.asset('assets/images/foo.png');❌ Unsafe
Use assets_genImage.asset(Assets.assets_images_foo_png);✅ Good

Getting Started #

Install #

dev_dependencies:
  assets_gen: any # Replace 'any' with version number.
  build_runner: any # Optional.

Usage #

Call directly (Recommend)Use build_runner
Run a single build and exit.flutter pub run assets_gen buildflutter pub run build_runner build
Continuously run builds as you edit files.flutter pub run assets_gen watchflutter pub run build_runner watch

Note: Call assets_gen script directly will take effect on the target package and all it's dependencies.

More info about pub-run and build_runner.

Options #

# Specify an assets_gen section in pubspec.yaml
flutter:
  assets:
    - path/to/asset
assets_gen:
  ...
optiontypedefault value
enablebooltrueEnable or not.
outputStringassets.dartOutput position, always under lib/.
class_nameStringAssetsThe generated class name.
gen_package_pathbooltrueWhether the builder should generate extra const variable with package info, e.g. packages/${package}/path/to/foo.png
ignore_resolutionbooltrueWhether the builder should ignore resolution variant. e.g. path/to/3.0x/foo.png will be ignored.
omit_path_levelsint0The path levels of generated key that the builder will omit. e.g. if levels is 2, the key of path/to/foo.png is foo_png.
excludeListnoneListed assets in exclude will be ignored in generated class. It supports glob syntax.
pluralsListnonePlurals support. e.g. Specify a plural - assets/vip/*.svg will generate a function like static String assets_vip_x_svg(Object p0) => 'assets/vip/${p0.toString()}.svg';.
6
likes
80
pub points
29%
popularity

The assets_gen package helps you to generate a .dart file that contains all assets according to `pubspec.yaml`.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

chenenyux@gmail.com

License

Apache 2.0 (LICENSE)

Dependencies

ansicolor, args, build, glob, logging, path, watcher, yaml

More

Packages that depend on assets_gen