OneOf<T> constructor

OneOf<T>(
  1. T? resolve(
    1. dynamic json,
    2. NyResponse response
    )
)

Decodes with resolve, which gets the body and the whole response and returns the value, or null for a shape it doesn't recognise.

OrderResult: OneOf<OrderResult>((json, response) => switch ((response.statusCode, json)) {
  (200, {'status': 'placed'}) => OrderPlaced.fromJson(json),
  (200, _) => OrderPending.fromJson(json),
  _ => null,
}),

Implementation

OneOf(this.resolve);