Skip to content
pubscout

built_value_generator

8.13.0, released 3 months ago by google.dev

Generates immutable value types, enum classes, and JSON serializers for Dart.

Flutter Favorite
$ flutter pub add built_value_generator
Source repository

What it does

It uses build_runner to generate boilerplate code for immutable value objects, enum classes, and serializers. This allows you to work with robust data models with value equality, builders, and custom hooks without writing the repetitive code yourself.

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

Use it when

  • You need immutable models with builder patterns and value equality.
  • You require robust JSON serialization with support for generics and complex object graphs.

Skip it when

  • You prefer mutable state or simple data classes without code generation.
  • You want a simpler serialization solution without the boilerplate of builders.

Strengths

  • Full support for object-oriented design, interfaces, and generics in serialization.
  • Immutable collections and validation hooks out of the box.

Weaknesses

  • Requires code generation and the build_runner tool.
  • Steeper learning curve and more boilerplate than some newer alternatives.

Setup

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

Requires adding built_value as a dependency and built_value_generator and build_runner as dev dependencies, then running build_runner.

abstract class Person implements Built<Person, PersonBuilder> {
  static Serializer<Person> get serializer => _$personSerializer;
  int get id;
  String? get firstName;
  Person._();
  factory Person([void Function(PersonBuilder) updates]) = _$Person;
}

Alternatives

Packages that do the same job and could replace built_value_generator.

  • freezed

    Offers union types and pattern matching with a more concise syntax for immutable classes.

  • json_serializable

    Generates JSON serialization for standard classes without requiring immutable builders.

Works with

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