flutter_gen
5.15.0, released 4 months ago by wasabeef.jp
A code generator for your assets, fonts, and colors to eliminate string-based APIs.
What it does
Generates strong-typed Dart classes and properties from pubspec.yaml asset paths, colors, and fonts. It provides compile-time safety and prevents typos when accessing application assets.
AI-written summary of version 5.15.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want compile-time safety for your asset paths, fonts, and colors.
- You want to avoid using raw strings like 'assets/images/logo.png' throughout your codebase.
Skip it when
- You prefer dynamic asset loading or runtime string-based asset paths.
- Your project does not use code generation tools.
Strengths
- Eliminates typo-prone string-based asset APIs.
- Integrates well with popular packages like flutter_svg, lottie, and rive.
- Supports build_runner and pub workspaces.
Weaknesses
- Requires running code generation (build_runner) when assets change.
- Adds a build step and dependency footprint to the project.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 6
Add build_runner and flutter_gen_runner to dev_dependencies in pubspec.yaml, configure flutter_gen options, and run build_runner.
Widget build(BuildContext context) {
return Assets.images.profile.image();
}Alternatives
Packages that do the same job and could replace flutter_gen.
- build
Package for authoring build_runner compatible code generators.
87Compare - pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare - code_assets
Provides the hook protocol specification for bundling native code with Dart packages.
88Compare - riverpod_generator
Generates Riverpod providers from annotated functions using build_runner.
85Compare
Works with
Packages commonly used together with flutter_gen: ones it builds on, ones built on it, and its own family.
- yamlflutter_gen depends on itA Dart library for parsing YAML documents into Dart data structures.
- globflutter_gen depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- argsflutter_gen depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- loggingflutter_gen depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- flutter_gen_runnerSame familyGenerates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.