🚧 Experimental 🚧
Experimental support for data classes in Dart using macros.
import 'package:struct_annotation/struct_annotation.dart';
@Struct()
class Person {
final String name;
final int age;
}
void main() {
final jane = Person(name: 'Jane', age: 42);
final john = jane.copyWith(name: 'John');
print(jane); // Person(name: Jane, age: 42)
print(john); // Person(name: John, age: 42)
print(jane == jane.copyWith()); // true
print(john == john.copyWith(age: 21)); // false
}
-
Switch to the Flutter
master
channelflutter channel master
-
Add
package:struct_annotation
to yourpubspec.yaml
dependencies: struct_annotation: ^0.0.0-dev.1
-
Enable expe 5563 rimental macros in
analysis_options.yaml
analyzer: enable-experiment: - macros
-
Use the
@Struct
annotation (see above example). -
Run it
dart --enable-experiment=macros run main.dart
Requires Dart SDK >= 3.5.0-152.0.dev