fallbackUnion property

String? fallbackUnion
final

Determines which constructor should be used when there is no matching one through constructor name or using FreezedUnionValue

By default, Freezed generates code that will throw FallThroughError when type is not matched through constructor name or using FreezedUnionValue. You can override this behavior by providing it's name or default to use default constructor

@Freezed(fallbackUnion: 'fallback')
class MyResponse with _$MyResponse {
  const factory MyResponse.special(String a, int b) = MyResponseSpecial;
  const factory MyResponse.fallback(String a, int b) = MyResponseFallback;

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

The constructor will be chosen as follows:

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

Implementation

final String? fallbackUnion;