finds.dev← search

// the find

rrousselGit/freezed

★ 2,182 · Dart · updated Jun 2026

Code generation for immutable classes that has a simple syntax/API without compromising on the features.

Freezed is a Dart/Flutter code generator that eliminates the boilerplate of writing immutable data classes — `toString`, `==`, `hashCode`, `copyWith`, and JSON serialization. It also handles sealed union types with proper pattern matching support. If you're writing Flutter apps with anything resembling a model layer, you'll use this or reinvent it poorly.

The deep copy syntax (`company.copyWith.director.assistant(name: 'John')`) is genuinely clever — it solves nested immutable updates without the usual pyramid of `copyWith` calls. Union/sealed class support integrates directly with Dart 3's native pattern matching rather than fighting it. The split between `freezed` (dev dependency, code generator) and `freezed_annotation` (runtime dependency) is the right architecture — you're not shipping the generator to production. Test suite coverage is thorough: separate integration files per feature, bidirectional tests, regression cases.

The `part` file requirement is a build_runner tax that pollutes every file and makes the initial setup annoying — you get confusing errors until you've run `dart run build_runner watch` at least once. Adding methods to primary-constructor classes requires a private empty constructor (`const Person._()`) that's a non-obvious gotcha and trips up almost everyone the first time. The JSON union type discrimination relies on a `runtimeType` key in the payload by default, which will silently fail or produce wrong types if you're consuming an API that uses a different discriminator field. Generated `.freezed.dart` files are verbose and large; in big projects, they slow down the analyzer noticeably.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →