Skip to content
pubscout

built_value

8.13.0, released 3 months ago by dart.dev

Immutable value types with builders, enum classes and JSON serialization for Dart.

Flutter FavoriteWASM-readyRock solid
$ flutter pub add built_value
Source repository

What it does

Provides a runtime library to define immutable data models using the builder pattern. Supports enum‑like classes and full JSON (de)serialization, working together with built_collection.

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

Use it when

  • You need strongly typed, immutable models with builders
  • You require robust JSON serialization that handles generics and nested built collections
  • You want enum‑style classes with additional behavior

Skip it when

  • You prefer a lightweight solution without code generation
  • Your project is small and a simple json_serializable approach is sufficient

Strengths

  • Zero‑runtime reflection – fast and safe
  • Full support for generics, nested built collections, and custom serializers
  • Builder pattern enforces immutability and safe updates

Weaknesses

  • Requires build_runner and a generator dev dependency
  • Steeper learning curve compared to plain json_serializable
  • Adds extra build step to the CI pipeline

Setup

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

Add built_value_generator and build_runner as dev_dependencies, then run `dart run build_runner build` (or watch).

abstract class Person implements Built<Person, PersonBuilder> {
  String get name;
  int get age;

  Person._();
  factory Person([void Function(PersonBuilder) updates]) = _$Person;
}

// Run `dart run build_runner build` to generate the *.g.dart file.

Alternatives

Packages that do the same job and could replace built_value.

  • freezed

    Provides similar immutable data classes with union types and less boilerplate

  • json_serializable

    Simpler code‑gen for JSON (de)serialization without the builder pattern

Works with

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