Skip to content
pubscout

freezed

4.0.3, released 5 weeks ago by dash-overflow.net

Code generation for immutable classes, tagged unions, and cloning without boilerplate.

Flutter FavoriteRock solid
$ flutter pub add freezed
Source repository

What it does

Freezed is a code generator for Dart that automatically generates boilerplate for immutable classes, such as constructors, copyWith methods, toString overrides, equality operators, and JSON serialization. It also supports union types, deep copying, and custom methods via a simple syntax.

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

Use it when

  • You need to create complex immutable data models and state classes in Dart or Flutter.
  • You want automatic support for copyWith, equality, hashCode, and toString without writing manual code.
  • You are implementing union types or tagged data models.

Skip it when

  • You prefer completely avoiding build_runner and code generation tools in your project workflow.
  • You are working with simple mutable objects that do not require immutability or cloning.

Strengths

  • Significantly reduces boilerplate code for data models.
  • Supports union types, deep cloning, default values, and asserts.
  • Integrates seamlessly with json_serializable for de/serialization.

Weaknesses

  • Requires running a code generator (build_runner) during development.
  • Can introduce steep debugging curves when generated files go out of sync.

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
11

Requires adding build_runner, freezed, and freezed_annotation to pubspec.yaml and running the build_runner watch command.

import 'package:freezed_annotation/freezed_annotation.dart';

part 'main.freezed.dart';
part 'main.g.dart';

@freezed
abstract class Person with _$Person {
  const factory Person({
    required String firstName,
    required String lastName,
    required int age,
  }) = _Person;

  factory Person.fromJson(Map<String, Object?> json) => _$PersonFromJson(json);
}

Alternatives

Packages that do the same job and could replace freezed.

  • json_serializable

    If you specifically need JSON parsing without the broader immutable data class features of Freezed.

Works with

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