Freezed: a Dart code generator that writes the constructor, copyWith, equality and unions for you
Code generation for immutable classes that has a simple syntax/API without compromising on the features.
At a glance
- What is it?
- Freezed generates the repetitive parts of Dart data classes through build_runner: constructors, toString, equality, copyWith, JSON hooks and tagged unions. This covers the three-package install, the part-file requirement, the two ways to declare a model and where the README leaves gaps.
- Who is it for?
- Use Freezed when a Dart or Flutter project has many immutable models and you already accept a build_runner step. Skip it for a handful of simple classes, where hand-written code avoids a generated file and a watcher process.
- Can I use it commercially?
- The repository metadata does not identify a licence. Check the project’s published terms and any component-specific licences before reuse.
- Is it still maintained?
- Yes. The repository last received commits 3 days ago.
- What is it written in?
- Mainly Dart, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.
Star history
- rrousselGit/freezed2,199 ★ · +3
| Repository | 2026-10-08 | 2026-11-26 |
|---|---|---|
| rrousselGit/freezed | 2.2k | 2.2k |
3 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Four chores per model: constructor, overrides, copyWith and serialization
The README opens its motivation with a list of what a plain Dart model demands. You define a constructor and properties. You override toString, operator == and hashCode. You implement a copyWith method to clone the object. You handle serialization and deserialization.
Done by hand, the project says, this takes hundreds of lines that are error-prone and hurt the readability of the model. Freezed implements most of that for you so the file shows the definition of the model and little else.
The repository describes itself as yet another code generator for data classes, tagged unions, nested classes and cloning. The phrase yet another is the authors' own, and no comparison against other generators appears in the part of the README available here. If you are choosing between generators, the evidence for the decision has to come from outside this page.
The README is translated into Korean, Simplified Chinese, Japanese and Vietnamese, with links at the very top. The translations live under resources/translations in the repository.
Three packages get installed, and two of them stay dev dependencies
Freezed needs a typical build_runner setup. For a Flutter project the install is:
flutter pub add \
dev:build_runner \
freezed_annotation \
dev:freezed
# if using freezed to generate fromJson/toJson, also add:
flutter pub add json_annotation dev:json_serializableFor a plain Dart project, swap flutter pub for dart pub:
dart pub add \
dev:build_runner \
freezed_annotation \
dev:freezed
# if using freezed to generate fromJson/toJson, also add:
dart pub add json_annotation dev:json_serializableThat installs three packages. build_runner is the tool that runs code generators. freezed is the generator. freezed_annotation holds the annotations your own code imports.
The split explains the dev: prefixes. build_runner and freezed run on your machine at build time, so they stay out of the shipped app. freezed_annotation has no prefix because your model files import it directly. The JSON line adds json_annotation and a dev dependency on json_serializable, and only applies if Freezed generates fromJson and toJson.
The invalid_annotation_target warning needs an ignore entry when json_serializable is involved
Combining Freezed with json_serializable can trigger a lint. Recent versions of json_serializable and meta may require you to disable the invalid_annotation_target warning. The fix goes in analysis_options.yaml at the project root:
analyzer:
errors:
invalid_annotation_target: ignoreThe README links this section from its index with a heading that also mentions warnings in generated files. The text available does not cover that second case in detail, so a project with analyser warnings inside the .freezed.dart output has to follow the linked section.
Treat the ignore as a project-wide setting. The entry sits at the root of the analyzer settings, so it applies to the whole project and not only to Freezed models. A team with strict lint rules should decide whether that is acceptable before pasting it in.
A model file needs the annotation import and a part line, or nothing generates
Running the generator is one command:
dart run build_runner watch -dWatch mode keeps a process alive and rebuilds when files change. The -d flag is as the README gives it. Like most generators, Freezed needs your file to import the annotation package and to use the part keyword at the top. A file that uses Freezed starts with:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'my_file.freezed.dart';The part line names the generated file, so the name must match your source file. Forget it and the generated code has nowhere to attach.
The README also recommends importing package:flutter/foundation.dart, because that import brings classes that make an object readable in Flutter's devtool. If you import foundation.dart yourself, Freezed adds the import automatically, so the manual line is optional in practice.
Every model therefore comes with a second file in the repository tree or in your build output. Where you commit the generated files is a team decision the README does not make for you.
Primary constructors simulate a Dart language proposal with factory, and classic classes get less
Freezed offers two ways to build a data class. With primary constructors, you define a constructor and Freezed generates the matching fields. The README says this simulates the Primary Constructor proposal from the Dart language repository (issue 2364) by using a factory constructor.
With classic classes, you write a normal Dart class and Freezed handles only toString, equality and copyWith. The scope difference is the whole point of the choice. A classic class keeps your own fields and constructor, so you gain less generated code but lose nothing of your hand-written structure. A primary constructor generates the fields, so the declaration shrinks, and your class shape is tied to what the factory expresses.
The index shows what primary constructors support: getters and methods, asserts, default values, non-constant default values, extending classes, mutable classes and allowing mutation of lists, maps and sets. The detail of each sits in the later README sections, which are cut off in the README text I could read.
Union types, JSON and the legacy when and map helpers sit behind the index
The index lists how copyWith works, with a deep copy section under it, plus decorators and comments, then FromJson and ToJson. The JSON entries cover classes with multiple constructors and deserializing generic classes.
Union types have their own block: shared properties, pattern matching to read non-shared properties, mixins and interfaces for individual classes, and ejecting an individual union case. Under it sits a group labelled legacy pattern matching utilities, with When and Map. The README labels them legacy, and a separate entry covers using pattern matching to read non-shared properties.
Configuration can change behaviour for a specific model or for the entire project. The README then lists utilities: a Freezed extension for VSCode, one for IntelliJ and Android Studio, a linting section and a third-party tool called DartJ.
Because the README text available stops at the model-creation heading, none of those sections can be quoted here. Anyone relying on a feature from that index, such as deep copy, should read the linked section and test it on a real model before depending on it.
Version 3.0.0 broke compatibility, no releases are tagged and the licence field is empty
Migrating from 2.0.0 to 3.0.0 has its own heading at the top of the README. It points to the changelog entry dated 2025-02-25 and a migration guide inside packages/freezed. The announcement leads the document, so a 2.0.0 user upgrading should expect changes that need reading, not a drop-in bump.
The repository has no GitHub releases, so versions are tracked through pub.dev and the changelog. The last push landed on 2026-10-25, and the project is not archived.
The licence field shows as unknown in the repository metadata, so check the LICENSE file inside packages/freezed or the pub.dev page before shipping a product on it. The root package.json is described in its own comment as configuring sponsorkit and nothing else, so it has no bearing on the library.
The root also holds a benchmarks directory, but no results appear in the README text, so no performance claim can be made.
Editorial conclusion
Use Freezed when a Dart or Flutter project has many immutable models and you already accept a build_runner step. Skip it for a handful of simple classes, where hand-written code avoids a generated file and a watcher process. Before adopting, check the licence on pub.dev, since GitHub shows none, and read the 3.0.0 migration guide if you are coming from 2.0.0.
Frequently asked questions
What is Freezed in Flutter?
Freezed is a code generator for Dart data classes, tagged unions, nested classes and cloning. It runs through build_runner and writes the constructor, toString, equality and copyWith parts that you would otherwise write by hand.
Is there a Freezed alternative for Flutter?
The Freezed README names no alternatives and describes itself as yet another code generator for data classes. Any comparison has to come from other sources, such as the pub.dev page.
What does freezed mean as a package name?
Freezed is the name of the Dart code generator at pub.dev/packages/freezed. The README does not explain the spelling, and its job is generating immutable data classes.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/rrousselgit-freezed)Star history chart for your README
[](https://hysenlabs.com/projects/rrousselgit-freezed)Was this useful?