fromJson static method

OfferPrice? fromJson(
  1. dynamic value
)

Returns a new OfferPrice 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 OfferPrice? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();
    final keys = json.keys.toSet();
    if (const <String>{'amount', 'currency'}.containsAll(keys) && keys.containsAll(const <String>{'amount', 'currency'})) {
      final variant = FixedPrice.fromJson(json);
      return variant == null ? null : OfferPrice(variant);
    }
    if (const <String>{'min', 'max', 'currency'}.containsAll(keys) && keys.containsAll(const <String>{'currency', 'max', 'min'})) {
      final variant = PriceRange.fromJson(json);
      return variant == null ? null : OfferPrice(variant);
    }
    throw FormatException('The properties $keys fit no variant of OfferPrice');
  }
  return null;
}