With class

Marks a union type to mixin the class type or stringType. In the case below City will mixin with GeographicArea.

@freezed
abstract class Example with _$Example {
  const factory Example.person(String name, int age) = Person;

  @With(GeographicArea)
  const factory Example.city(String name, int population) = City;
}

In case you need to mixin a generic class, due to the fact that annotations can't have type arguments, you must use the With.fromString('stringType') constructor and provide the type as a String.

@freezed
abstract class Example with _$Example {
  const factory Example.person(String name, int age) = Person;

  @With.fromString('AdministrativeArea<House>')
  const factory Example.street(String name) = Street;

  @With(GeographicArea)
  const factory Example.city(String name, int population) = City;
}

Note: You need to make sure that you comply with the interface requirements by implementing all the abstract members. If the mixin has no members or just fields, you can fulfil the interface contract by adding them in the constructor of the union type. Keep in mind that if the mixin defines a method or a getter, that you implement in the class, you need to use the Custom getters and methods instructions.

Constructors

With(Type type)
const
With.fromString(String stringType)
const

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
stringType String
final
type Type
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited