2. First Serializable

You can create serializable classes by annotating the with @serializable and providing an unnamed constructor for all final serializable fields. This must either be the default constructor, or a constructor named dog. Additionally, you should add the self-referencing Dataclass mixin.

@serializable
class Person with Dataclass<Person> {

  String name;
  int age;
  Set<String>? tags;
  
  Person(this.name, this.age, this.tags);
  
}

// Enums can also be serialized!
@serialzable
enum MyEnum {
  a,b,c;
}

For other types of structure definitions, have a look at Conformity.

Last updated