Skip to content
pubscout

flutter_asset_generator

1.2.0, released 2 years ago by fluttercandies.com

Generates Dart constant files for pubspec.yaml assets to avoid manual string paths.

$ flutter pub add flutter_asset_generator
Source repository

What it does

Scans assets defined in pubspec.yaml and automatically generates a Dart resource file containing static constants for each asset path. Supports customization via configuration files, include/exclude rules, and preview comments.

AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to avoid hardcoding asset strings throughout your Flutter app
  • You prefer auto-generated resource classes (similar to R files in Android)

Skip it when

  • You prefer manually managing asset paths as strings
  • You need dynamic runtime asset loading without code generation

Strengths

  • Automates asset path constants generation
  • Supports custom include/exclude rules and replacement rules via fgen.yaml
  • Provides file preview comments in generated code

Weaknesses

  • Requires running a CLI tool or watching changes
  • Naming conflicts can occur if different directories contain files with identical generated field names

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
6

Install globally via pub or run from source, then use the fgen command or configure fgen.yaml in the project root.

class R {
  const R._();
  static const String ASSETS_CAMERA_PNG = 'assets/camera.png';
}

Alternatives

Packages that do the same job and could replace flutter_asset_generator.

  • pubspec_extract

    Extracts Dart pubspec.yaml file and generates pubspec.dart at build time

  • protobuf

    Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.

  • winmd

    Inspect and generate Windows Metadata (.winmd) files based on ECMA-335.

  • assets_generator

    Automatically generates asset configs in YAML and Dart constants for single projects and modules.

Works with

Packages commonly used together with flutter_asset_generator: ones it builds on, ones built on it, and its own family.