Skip to main content
Freezed is a Dart code-generation package that produces immutable value classes with copyWith, structural equality, and toString for free. If your app already uses Freezed for domain models, Cindel can persist those models directly — as long as you stay within the two supported shapes. This page explains which Freezed patterns work with Cindel, how to set them up, and what to avoid.

Supported Shapes

Cindel supports exactly two Freezed shapes for collections:

Classic class

A @freezed class with a concrete constructor and @override final fields in the class body.

Single primary factory

A @freezed abstract class whose entire shape is defined by one const factory constructor.
Freezed union and sealed models — classes that declare multiple named factory constructors to represent different states — are not supported as Cindel collections. If you need sealed modeling alongside persistence, keep your Freezed union types separate from your Cindel collection classes.

Primary Factory Style

In the primary factory style, you place Cindel field annotations (@Index, @Enumerated, @ignore, and so on) directly on the factory constructor parameters.
You can combine Cindel annotations with Freezed annotations on the same parameter:

IDs in the Primary Factory Style

Freezed primary factory models are immutable — Cindel cannot write an auto-assigned ID back into the object after put. For this reason, dbId must be required in the factory and you supply its value explicitly when constructing the object.
If you want Cindel to manage IDs automatically, use a regular mutable class or the classic Freezed class style instead — those styles have an assignable dbId field that works with autoIncrement.

Classic Class Style

In the classic class style, the Freezed model uses a concrete constructor and declares fields in the class body with @override final. Cindel annotations go on the field declarations, exactly as in a regular Cindel collection class.
Use this style when you want explicit field declarations visible in the class body and prefer concrete classes over abstract ones.

Required part Directives

Freezed collections need two part directives: one for Freezed output and one for Cindel output.
Run both build steps together:

Dev Dependencies

Add both freezed and freezed_annotation to your project alongside the Cindel generator.

Rules That Still Apply

A Freezed collection follows every rule that applies to a regular Cindel collection:
1

One persisted ID

The model must have exactly one Id dbId field. Classic class style supports autoIncrement; primary factory style requires an explicit value at construction time.
2

Supported field types

All persisted fields must use types Cindel supports — primitives, DateTime, Duration, enums with @Enumerated, embedded objects, and flat lists of those types.
3

Stable stored names

@Collection(name: ...) and @Name(...) values must remain stable once real data exists.
4

Single constructor shape

The Freezed model must have exactly one constructor shape. Do not add named union factories.
Embedded objects can also be Freezed models, using either supported style. Apply @embedded (or @Embedded()) in place of @Collection and omit the dbId field. All other Freezed and embedded constraints still apply.