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.
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
75Compare - protobuf
Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.
84Compare - winmd
Inspect and generate Windows Metadata (.winmd) files based on ECMA-335.
70Compare - assets_generator
Automatically generates asset configs in YAML and Dart constants for single projects and modules.
60Compare
Works with
Packages commonly used together with flutter_asset_generator: ones it builds on, ones built on it, and its own family.
- yamlflutter_asset_generator depends on itA Dart library for parsing YAML documents into Dart data structures.
- globflutter_asset_generator depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- ioflutter_asset_generator depends on itUtilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
- dart_styleflutter_asset_generator depends on itProvides an API and CLI to format Dart source code automatically.
- argsflutter_asset_generator depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.