fromJson static method

Room? fromJson(
  1. dynamic value
)

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

Implementation

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

    return Room(
      roomGroupKey: mapValueOfType<String>(json, r'roomGroupKey'),
      name: mapValueOfType<String>(json, r'name')!,
      description: mapValueOfType<String>(json, r'description'),
      beds: Bed.listFromJson(json[r'beds']),
      maxOccupancy: mapValueOfType<int>(json, r'maxOccupancy'),
      sizeSquareMeters: json[r'sizeSquareMeters'] == null
          ? null
          : num.parse('${json[r'sizeSquareMeters']}'),
      amenities: json[r'amenities'] is Iterable
          ? (json[r'amenities'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      imageUrls: json[r'imageUrls'] is Iterable
          ? (json[r'imageUrls'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      roomIndex: mapValueOfType<int>(json, r'roomIndex')!,
      adultsCount: mapValueOfType<int>(json, r'adultsCount'),
      childrenCount: mapValueOfType<int>(json, r'childrenCount'),
      childrenAges: json[r'childrenAges'] is Iterable
          ? (json[r'childrenAges'] as Iterable).cast<int>().toList(growable: false)
          : const [],
    );
  }
  return null;
}