Skip to content
pubscout

build

5.0.0, released 5 weeks ago by dart.dev

Package for authoring build_runner compatible code generators.

$ flutter pub add build
Source repository

What it does

A package for writing code generators, called builders, that run with build_runner. It defines the core Builder interface and build step APIs for reading, analyzing, and writing files.

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

Use it when

  • You are developing a custom build_runner compatible code generator package.
  • You need to implement the low-level Builder interface to generate code based on inputs.

Skip it when

  • You are just writing a standard application or package that uses existing code generators rather than authoring one.
  • You want a higher-level helper for annotation-based builders (use source_gen instead).

Strengths

  • Provides the core underlying Builder interface used across the Dart build ecosystem.
  • Gives easy access to the analyzer for processing and resolving Dart source code.

Weaknesses

  • Low-level compared to source_gen, requiring more manual handling of build steps.
  • Major version updates can introduce breaking changes for packages implementing BuildStep.

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
6

Requires configuration with build_runner to run builders.

class CopyBuilder implements Builder {
  @override
  final buildExtensions = const {
    '.txt': ['.txt.copy']
  };

  @override
  Future<void> build(BuildStep buildStep) async {
    final inputId = buildStep.inputId;
    final outputId = inputId.addExtension('.copy');
    final contents = await buildStep.readAsString(inputId);
    await buildStep.writeAsString(outputId, contents);
  }
}

Alternatives

Packages that do the same job and could replace build.

Works with

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