// the find
felangel/data_class
Experimental support for data classes in Dart using macros.
An experiment from Felix Angelov, the author of bloc, that uses Dart's macros feature to generate const constructors, copyWith, toString, and value equality for annotated classes. It is for Dart developers who wanted freezed-style data classes without build_runner and were willing to run on an experimental language feature.
There is no build_runner step and no generated part file to check in, because the macro runs in the analyzer and the output cannot drift out of date. The test tree covers more shapes than the feature list suggests, including empty classes, nested subclasses, named, positional, and optional positional fields, nullable fields, generics, and static fields, which are the cases hand-rolled generators usually get wrong. The generated constructor is an ordinary const constructor with required named parameters, so call sites look the same as they would for a hand-written class. The lib is split into constructable, copyable, and stringable macros, so each piece can be read and tested on its own.
It is experimental by design: it needs --enable-experiment=macros at run time and the macros flag in analysis_options, and the Dart team has since pulled back on macros, so there is no stable path for this to land on. It is also stale. The last push was 2024-10-16, nearly two years ago, and the README still pins Dart >= 3.5.0, so expect breakage against newer SDKs with no fix coming. The README does not say how copyWith tells an omitted nullable argument from an explicit null, which is the standard trap for this pattern, and the example only uses non-nullable fields. Value equality is the other usual failure point: the README says nothing about List or Map fields, which compare by identity under plain ==.