fromJson static method

FulfillmentUpdate? fromJson(
  1. dynamic value
)

Returns a new FulfillmentUpdate from a decoded JSON object, or null for something that is not an object. Throws a FormatException when no variant fits: skipping it would hide a purchase or a price.

Implementation

static FulfillmentUpdate? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();
    switch (json[r'productType']) {
      case "esim":
        final variant = EsimFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
      case "hotel":
        final variant = HotelFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
      case "flight":
        final variant = FlightFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
      case "giftCard":
        final variant = GiftCardFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
      case "airtime":
        final variant = AirtimeFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
      case "utility":
        final variant = UtilityFulfillmentUpdate.fromJson(json);
        return variant == null ? null : FulfillmentUpdate(variant);
    }
    throw FormatException('Unknown productType ${json[r'productType']} in FulfillmentUpdate');
  }
  return null;
}