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.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.
IDs in the Primary Factory Style
Freezed primary factory models are immutable — Cindel cannot write an auto-assigned ID back into the object afterput. For this reason, dbId must be required in the factory and you supply its value explicitly when constructing the object.
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.
Required part Directives
Freezed collections need two part directives: one for Freezed output and one for Cindel output.
Dev Dependencies
Add bothfreezed 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.