freezed
Code generation for immutable classes that has a simple syntax/API without compromising on the features.
4.0.0
2.5M downloads/mo
#234 most downloaded on pub.dev
rrousselGit/freezed
What this package is like to depend on
Last release today
22 Aug 2026
Ships fairly regularly
a new release about every 2 months
Nearly every release is documented
notes for 128 of 129 stable releases
1 version withdrawn
withdrawn after publishing
7 years old
144 releases · first in 2020
10 releases in the last 12 months
see the full history below
Release timeline
144 releases · Feb 2020 to Aug 2026Releases
latest 60 of 144-
4.0.022 Aug 2026Release notes
Open source →- Fix
==/copyWithwhen immutable collections are enabled yet non-factory constructors are used. - Fix
(int,)records incorrectly generated - Support analyzer 13.0
- Support primary constructors
- Breaking: No-longer support
finalkeyword inside constructor parameter. This is due to Dart 3.13 no-longer allowing this syntax. This prevents@unfreezedfrom defining immutable fields.
- Fix
-
4.0.0-dev.313 Jun 2026 pre-releaseRelease notes
Open source →- Fix
==/copyWithwhen immutable collections are enabled yet non-factory constructors are used.
- Fix
-
4.0.0-dev.213 Jun 2026 pre-release -
4.0.0-dev.111 Jun 2026 pre-releaseRelease notes
Open source →- Support analyzer 13.0
- Support primary constructors
- Breaking: No-longer support
finalkeyword inside constructor parameter. This is due to Dart 3.13 no-longer allowing this syntax. This prevents@unfreezedfrom defining immutable fields.
-
3.2.6-dev.123 Apr 2026 pre-release -
3.2.503 Feb 2026 -
3.2.430 Dec 2025 -
3.2.310 Sep 2025 -
3.2.209 Sep 2025 -
3.2.109 Sep 2025 -
3.2.018 Jul 2025Release notes
Open source →- Use
build3.0.0-dev. - Use
source_gen3.0.0-dev. - Support Dart 3.8.0 and analyzer 7.5.9 as a minumum.
- Use
-
3.1.002 Jul 2025Release notes
Open source →- Added
when/mapback - Stop writing
// dart format width=80to the generated freezed files.
- Added
-
3.0.605 Apr 2025 -
3.0.505 Apr 2025Release notes
Open source →- Fix ==/hashCode when using inheritance.
The generated ==/hashCode now call
super == otherwhen necessary. - Fix an issue with
DiagnosticableandtoString - Fix ejecting union cases when more than one class is defined in a file
- Fix a copyWith bug when a constructor parameter has no matching property
- Fix null exception in some cases when using generic classes and copyWith
- Fix ==/hashCode when using inheritance.
The generated ==/hashCode now call
-
3.0.416 Mar 2025Release notes
Open source →- Update docs (thanks to @lishaduck)
- Support Dart 3.6.0 and analyzer 6.9.0 as a minimum.
-
3.0.302 Mar 2025 -
3.0.227 Feb 2025Release notes
Open source →- Fix various deep-copy bugs
- Throw when using
extends/withbut not specifying aMyClass._()constructor - Throw when a Freezed class forgot to include
with _$MyClass - "Normal" classes shouldn't require
MyClass._()when they define getters/methods/...
-
3.0.127 Feb 2025 -
3.0.025 Feb 2025Release notes
Open source →New: Mixed mode
Freezed 3.0 is about supporting a "mixed mode".
From now on, Freezed supports both the usual syntax:@freezed sealed class Usual with _$Usual { factory Usual({int a}) = _Usual; }But also:
@freezed class Usual with _$Usual { Usual({this.a}); final int a; }This has multiple benefits:
- Simple classes don't need Freezed's "weird" syntax and can stay simple
- Unions can keep using the usual
factorysyntax
This also offers a way to use all constructor features, such as initializers or
super():class Base { Base(String value); } @freezed class Usual extends Base with _$Usual { Usual({int? a}) a = a ?? 0, super('value'); final int a; }New: Inheritance and non-constant default values.
When using Freezed, a common problem has always been the lack of
extendssupport and non-constant default values.Besides through "Mixed mode" mentioned above, Freezed now offers a way for
factoryconstructors to specify non-constant defaults and asuper(), by relying on theMyClass._()constructor:It also has another benefit:
Complex Unions now have a way to use Inheritance and non-constant default values, by relying on a non-factoryMyClass._()constructor.For context:
Before, when a Freezed class specified a property or method, it was required to specify aMyClass._()constructor:@freezed class Example with _$Example { // Necessary for helloWorld() to work Example._(); factory Example(String name) = _Example void helloWorld() => print('Hello $name'); }However, that
Example._()constructor was required to have no parameter.Starting Freezed 3.0, this constructor can accept any parameter. Freezed will then pass its values from other
factoryconstructors, based on name.In short, this enables extending any class:
class Subclass { Subclass.name(this.value); final int value; } @freezed class MyFreezedClass extends Subclass with _$MyFreezedClass { // We can receive parameters in this constructor, which we can use with `super.field` MyFreezedClass._(super.value): super.name(); factory MyFreezedClass(int value, /* other fields */) = _MyFreezedClass; }It also enables non-constant default values:
@freezed sealed class Response<T> with _$Response<T> { // We give "time" parameters a non-constant default Response._({DateTime? time}) : time = time ?? DateTime.now(); // Constructors may enable passing parameters to ._(); factory Response.data(T value, {DateTime? time}) = ResponseData; // If ._ parameters are named and optional, factory constructors are not required to specify it factory Response.error(Object error) = ResponseError; @override final DateTime time; }New: "Eject" union cases
Along with the mixed mode, it is also possible to eject a "union" case, by having it point to a custom class.
Concretely, you can do:
@freezed sealed class Result<T> with _$Result { Result._(); // Data does not exist, so Freezed will generate it as usual factory Result.data(T data) = ResultData; // We wrote a ResultError class in the same library, so Freezed won't do anything factory Result.error(Object error) = ResultError; } // We manually wrote `ResultError` class ResultError<T> extends Result<T> { ResultError(this.error): super._(); final Object error; }This combines nicely with "Mixed mode" mentioned previously, as extracted union cases can also be Freezed classes:
// Using freezed with a simple class: @freezed class ResultError<T> extends Result<T> { ResultError(this.error): super._(); final Object error; } // Or using a factory: @freezed class ResultError<T> extends Result<T> { ResultError._(): super._(); factory ResultError(Object error) = _ResultError; }This feature offers fine-grained control over every parts of your models.
Note: Unfortunately, it is kind of required to "extend" the parent class (so here
extends Result<T>). This is because Dart doesn't supportsealed mixin class, so you can't dowith Result<T>instead.Other changes:
- Breaking: Removed
map/whenand variants. These have been discouraged since Dart got pattern matching. - Breaking: Freezed classes should now either be
abstract,sealed, or manually implements_$MyClass. - When formatting is disabled (default), Freezed now generates
// dart format off. This prevents having to exclude generated file from formatting check in the CI. - It is now possible to have a private constructor for unions:
@freezed sealed class Result<T> with _$Result { // It wasn't possible to write _data before, but now is. factory Result._data(T data) = ResultData; factory Result.error(Object error) = ResultError; }
-
3.0.0-0.0.dev18 May 2024 pre-releaseNothing published for this version
-
2.5.806 Jan 2025 -
2.5.715 Jul 2024 -
2.5.609 Jul 2024 -
2.5.509 Jul 2024Release notes
Open source →- Stop using
JsonKey(ignore: true)in favour ofJsonKey(includeFromJson: false, includeToJson: false)(thanks to @lrsvmb) - Require json_annotation ^6.8.0
- Stop using
-
2.5.402 Jul 2024 -
2.5.314 May 2024 -
2.5.211 Apr 2024 -
2.5.108 Apr 2024 -
2.5.005 Apr 2024Release notes
Open source →- Added
format: falseflag in thebuild.yaml, to disable formatting in generated files. This can significantly improve performance, but may require updating your CI to not check that generated files are formatted. - Fixed an
InconsistentAnalysisException
- Added
-
2.4.805 Apr 2024 -
2.4.704 Feb 2024 -
2.4.615 Dec 2023 -
2.4.510 Oct 2023Release notes
Open source →Loosened
analyzerversion to support both ^5.13.0 and ^6.0.0 (thanks to @SunlightBro) -
2.4.410 Oct 2023 -
2.4.327 Sep 2023 -
2.4.203 Aug 2023 -
2.4.112 Jul 2023 -
2.4.011 Jul 2023 withdrawnRelease notes
Open source →- Allow enabling/disabling all
when/mapvariants at once (thanks to @gaetschwartz)
- Allow enabling/disabling all
-
2.3.505 Jun 2023 -
2.3.413 May 2023Release notes
Open source →- Fix allow dollar ($) in recursive class names (thanks to @andreasgangso)
- Fix deprecated warning with analyzer 5.12.0 (thanks to @SunlightBro)
- Remove warning when marking a class as
abstract
-
2.3.303 May 2023Release notes
Open source →- Fixed an issue with the generated code when classes contains a
$in their property/constructor/class name (thanks to @medz)
- Fixed an issue with the generated code when classes contains a
-
2.3.207 Dec 2022 -
2.3.106 Dec 2022 -
2.3.030 Nov 2022Release notes
Open source →-
Union types now expose properties with the same name but different type on the shared interface. (Thanks to @DevNico)
This allows doing:
@freezed class Union with _$Union { factory Union.first(int value) = _UnionFirst; factory Union.second(double value) = _UnionSecond; } void main() { Union union; num value = union.value; // No need for casting as "num" is the shared interface between int/double } -
Fixes copyWith not working with
nullon some scenarios. -
Fixes a stackoverflow error when continuously passing unmodifiable collections as parameter to freezed classes
-
fix: Deep copy now correctly handles cases where a property is a Freezed class with disabled
copyWith
-
-
2.2.126 Oct 2022 -
2.2.014 Oct 2022Release notes
Open source →- The generated
copyWithis now annotated by@useResult(thanks to @miDeb) - Improved performance of
copyWith(thanks to @miDeb) - Improved type inference when using
mapOrNull/whenOrNull(thanks to @DevNico) - Re-introduced
@With.fromStringand@Implements.fromStringto allow unions to implement generic types. (thanks to @rorystephenson) - fixes @Default for Strings containing (, [ or { (thanks to @hugobrancowb)
- fix Freezed incorrectly comparing primitives using
DeepCollectionEquality(thanks to @knaeckeKami) - fix image links (thanks to @SunlightBro)
- The generated
-
2.1.120 Sep 2022Release notes
Open source →- Bump Analyzer to 5.0.0
- Fix an issuee where Freezed fails to detect that the
DiagnosticableAPI is available
-
2.1.015 Jul 2022Release notes
Open source →- Add support for de/serializing generic Freezed classes (Thanks to @TimWhiting)
- Fixed a StackOverflow error when defining circular
exports (Thanks to @TimWhiting)
-
2.1.0+115 Jul 2022 -
2.0.512 Jul 2022 -
2.0.406 Jul 2022Release notes
Open source →Fixes a bug where using
@unfreezedon unions somehow still generated immutable properties. -
2.0.306 May 2022Release notes
Open source →- fix: performance regression with ==/hashCode/copyWith due to immutable collections (#653)
- fix: build.yaml decoding crash
- fix: remove annotations on internal properties related to immutable collections (#659)
-
2.0.3+112 May 2022 -
2.0.220 Apr 2022 -
2.0.120 Apr 2022Release notes
Open source →- Fixed a bug where the generated when/map methods were potentially invalid when using default values
- Fixed a bug where when/map methods were generated even when not necessary
-
2.0.019 Apr 2022Release notes
Open source →-
Breaking: freezed_annotation no-longer exports the entire package:collection
-
Breaking: Freezed no-longer generates
$MyClassTearOff. This feature is now available in Dart -
Breaking Removed
@Freezed(maybeMap: )&@Freezed(maybeWhen: )in favor of a separate:@Freezed(map: FreezedMap(...), when: FreezedWhenOptions(...)) -
Breaking: Freezed now converts Lists/Maps/Sets into UnmodifiableListView/UnmodifiableMapView/UnmodifiableSetView. This can be disabled for one class by specifying
@Freezed(makeCollectionsUnmodifiable: false). Alternatively, this can be configured inside thebuild.yamlfile -
Added parameters of
@Freezedto customize the generated code. This includes: fromJson, toJson, map, when, equal, toStringOverride, copyWith.These parameters allow disabling code that would otherwise be generated. It also allows forcing the generation even if it would otherwise not be generated.
-
Feat: Add screaming snake union case type (#617) (thanks to @zbarbuto)
-
Fix null exceptions in some cases when using typedefs (thanks to @smiLLe)
-
Support analyzer 4.0.0
-
Fix an issue with generic Freezed classes failing to compile when using
@With<Mixin<T>>()#614 -
Added
@unfreezedas a variant to@freezed, for mutable classes
-
-
1.1.129 Dec 2021Release notes
Open source →- Lints are now disabled inside generated files (requires Dart 2.15)
- Upgraded the analyzer version to 3.0.0
-
1.1.011 Dec 2021Release notes
Open source →Added support for disabling the generation of
maybeMap/maybeWhen(thanks to @Lyokone) -
1.0.205 Dec 2021Release notes
Open source →Fixed a regression with the ==/hashCode implementation generated for classes with custom implementations of
List/Map/... (see https://github.com/rrousselGit/freezed/issues/561) -
1.0.2+109 Dec 2021