fromJson static method

EventSchema? fromJson(
  1. dynamic value
)

Returns a new EventSchema instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static EventSchema? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'name'),
          'Required key "EventSchema[name]" is missing from JSON.');
      assert(json[r'name'] != null,
          'Required key "EventSchema[name]" has a null value in JSON.');
      assert(json.containsKey(r'code'),
          'Required key "EventSchema[code]" is missing from JSON.');
      assert(json[r'code'] != null,
          'Required key "EventSchema[code]" has a null value in JSON.');
      assert(json.containsKey(r'maps'),
          'Required key "EventSchema[maps]" is missing from JSON.');
      assert(json[r'maps'] != null,
          'Required key "EventSchema[maps]" has a null value in JSON.');
      assert(json.containsKey(r'duration'),
          'Required key "EventSchema[duration]" is missing from JSON.');
      assert(json[r'duration'] != null,
          'Required key "EventSchema[duration]" has a null value in JSON.');
      assert(json.containsKey(r'rate'),
          'Required key "EventSchema[rate]" is missing from JSON.');
      assert(json[r'rate'] != null,
          'Required key "EventSchema[rate]" has a null value in JSON.');
      return true;
    }());

    return EventSchema(
      name: mapValueOfType<String>(json, r'name')!,
      code: mapValueOfType<String>(json, r'code')!,
      content: EventContentSchema.fromJson(json[r'content']),
      maps: EventMapSchema.listFromJson(json[r'maps']),
      duration: mapValueOfType<int>(json, r'duration')!,
      rate: mapValueOfType<int>(json, r'rate')!,
      cooldown: mapValueOfType<int>(json, r'cooldown') ?? 0,
      price: mapValueOfType<int>(json, r'price'),
      transition: TransitionSchema.fromJson(json[r'transition']),
      cooldownExpiration: mapDateTime(json, r'cooldown_expiration', r''),
    );
  }
  return null;
}