Skip to content
pubscout

source_gen

4.3.1, released 5 weeks ago by tools.dart.dev

Source code generation builders and utilities for the Dart build system.

$ flutter pub add source_gen
Source repository

What it does

Provides a framework for writing Dart code builders and a convention for human and tool-generated code to coexist. Exposes a developer-friendly API on top of the analyzer and build packages.

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

Use it when

  • You are writing custom code generators for Dart libraries or annotations
  • You need to build custom Builders that consume and produce Dart code

Skip it when

  • You are simply looking to use existing generators like json_serializable or freezed without writing your own

Strengths

  • Exposes a developer-friendly API on top of lower-level analyzer and build packages
  • Supports multiple code generators integrating seamlessly in the same project via shared part builders

Weaknesses

  • Requires understanding of the Dart build system and analyzer APIs

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
9

Add source_gen to dependencies or dev_dependencies, and configure builders in a build.yaml file.

dependencies:
  source_gen:

dev_dependencies:
  build_runner:
  build_config:

Alternatives

Packages that do the same job and could replace source_gen.

Works with

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