fromJson static method

TransitionSchema? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static TransitionSchema? 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'map_id'),
          'Required key "TransitionSchema[map_id]" is missing from JSON.');
      assert(json[r'map_id'] != null,
          'Required key "TransitionSchema[map_id]" has a null value in JSON.');
      assert(json.containsKey(r'x'),
          'Required key "TransitionSchema[x]" is missing from JSON.');
      assert(json[r'x'] != null,
          'Required key "TransitionSchema[x]" has a null value in JSON.');
      assert(json.containsKey(r'y'),
          'Required key "TransitionSchema[y]" is missing from JSON.');
      assert(json[r'y'] != null,
          'Required key "TransitionSchema[y]" has a null value in JSON.');
      assert(json.containsKey(r'layer'),
          'Required key "TransitionSchema[layer]" is missing from JSON.');
      assert(json[r'layer'] != null,
          'Required key "TransitionSchema[layer]" has a null value in JSON.');
      return true;
    }());

    return TransitionSchema(
      mapId: mapValueOfType<int>(json, r'map_id')!,
      x: mapValueOfType<int>(json, r'x')!,
      y: mapValueOfType<int>(json, r'y')!,
      layer: MapLayer.fromJson(json[r'layer'])!,
      conditions: ConditionSchema.listFromJson(json[r'conditions']),
    );
  }
  return null;
}