path_gen 1.4.2 copy "path_gen: ^1.4.2" to clipboard
path_gen: ^1.4.2 copied to clipboard

All in one generator for your asset paths with support to transform .svg to .vec(opt-in).

Path Gen #

path_gen generates typed Dart asset paths from your asset directories. It can also compile SVG files to .vec with vector_graphics_compiler.

Features #

  • ✅ optionally generate .vec files
  • ✅ generate asset classes for arbitrary directory depth
  • ✅ scan raw assets such as PNG, JPEG, JSON, and SVG
  • ✅ cache the full asset pipeline with a hash-based manifest
  • ✅ configure input and generated Dart directories in pubspec.yaml

Install #

Add path_gen to the consumer app:

flutter pub add path_gen

Run it from that app's root:

dart run path_gen

Or install the executable globally:

dart pub global activate path_gen
path_gen

The global command reads the path_gen configuration from the pubspec.yaml in the current directory, so it does not need to be added as a dependency to each consumer app.

Configuration #

Configure the source asset and generated Dart directories in the consumer app's pubspec.yaml:

path_gen:
  input: assets
  output: lib/assets
  generate_all_getter: false
  transform_svg_to_vec: true
  update_flutter_assets: true

Both paths are relative to the app root. The generated file is app_asset.dart in the configured output directory. generate_all_getter adds a direct-files-only List<String> get all to generated classes.

Assets are scanned recursively. Raw files such as PNG, JPEG, JSON, and SVG are used directly. With transform_svg_to_vec: true, SVG output is written to a sibling *-bin directory and its top-level directory is added to a managed block in the app's flutter.assets. Set update_flutter_assets: false to prevent that update. Set transform_svg_to_vec to false to keep raw SVG paths and render them with your preferred package, such as flutter_svg.

For example:

assets/illustrations/animals/birds/eagle.png
assets/icons/post/ico1.svg

generates AppAsset.illustrations.animals.birds.eagle and AppAsset.icons.post.ico1.

Then run dart run path_gen at the app root. Make sure generated *-bin directories are included under flutter.assets when SVG compilation is enabled.

For assets like:

assets/icons/post/ico1.svg
assets/icons/post/ico3.svg

after running the command:

SvgPicture.asset(AppAsset.icons.post.ico1)

final postIcons = AppAsset.icons.post.all;

Compared with flutter_gen #

Like flutter_gen, path_gen generates typed asset paths. Unlike flutter_gen, it runs as a command when you choose, uses no build_runner, and can optionally compile SVG files to .vec.

1
likes
160
points
96
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

All in one generator for your asset paths with support to transform .svg to .vec(opt-in).

Repository (GitHub)
View/report issues

Topics

#asset #generation #vector

License

BSD-3-Clause (license)

Dependencies

args, crypto, path, vector_graphics_compiler, yaml

More

Packages that depend on path_gen