flutter_gen_runner
5.15.0, released 4 months ago by wasabeef.jp
Generates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.
What it does
It reads your pubspec.yaml configuration and asset folders to generate safe, static reference classes. This eliminates string typos when loading images, fonts, or colors in your widgets.
AI-written summary of version 5.15.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want type safety for asset paths, fonts, and colors in your Flutter app.
- You want to avoid runtime errors from typos in string-based asset paths.
Skip it when
- Your project does not use local assets, custom fonts, or generated color files.
- You prefer completely manual string references for resources.
Strengths
- Eliminates string-based asset paths and potential typos.
- Integrates seamlessly with build_runner and pubspec.yaml configurations.
- Supports specialized integrations like flutter_svg, rive, and lottie.
Weaknesses
- Requires running a code generator whenever assets are added or modified.
- Adds build-time overhead to your project development workflow.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 9
Add flutter_gen_runner to your dev_dependencies and build_runner to your pubspec.yaml, then configure flutter_gen 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_runner.
- 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 - mobx_codegen
Generates MobX store boilerplate from @observable, @computed and @action annotations.
85Compare
Works with
Packages commonly used together with flutter_gen_runner: ones it builds on, ones built on it, and its own family.
- yamlflutter_gen_runner depends on itA Dart library for parsing YAML documents into Dart data structures.
- cryptoflutter_gen_runner depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- globflutter_gen_runner depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- package_configflutter_gen_runner depends on itRead and write Dart package configuration files.
- buildflutter_gen_runner depends on itPackage for authoring build_runner compatible code generators.
- build_configflutter_gen_runner depends on itFormat definition and support for parsing build.yaml configuration.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.
- flutter_genSame familyA code generator for your assets, fonts, and colors to eliminate string-based APIs.