Skip to content
pubscout

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.

WASM-readyRock solid
$ flutter pub add flutter_gen
Source repository

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.

  • pigeon

    Type-safe code generator for communication between Flutter and host platforms.

  • code_assets

    Provides the hook protocol specification for bundling native code with Dart packages.

  • riverpod_generator

    Generates Riverpod providers from annotated functions using build_runner.

Works with

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