FreezedUnionValue class

An annotation used to specify how a union type will be serialized.

By default, Freezed generates the value based on the name of the constructor. You can override this behavior by annotating constructor and providing custom value.

@freezed
class MyResponse with _$MyResponse {
  const factory MyResponse(String a) = MyResponseData;

  @FreezedUnionValue('SpecialCase')
  const factory MyResponse.special(String a, int b) = MyResponseSpecial;

  factory MyResponse.fromJson(Map<String, dynamic> json) => _$MyResponseFromJson(json);
}

The constructor will be chosen as follows:

[
  {
    "runtimeType": "default",
    "a": "This JSON object will use constructor MyResponse()"
  },
  {
    "runtimeType": "SpecialCase",
    "a": "This JSON object will use constructor MyResponse.special()",
    "b": 42
  }
]

Constructors

FreezedUnionValue(String value)
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String
final

Methods

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

Operators

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