fromJson static method

Chat? fromJson(
  1. dynamic value
)

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

Implementation

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

    return Chat(
      id: mapValueOfType<int>(json, r'id'),
      tutor: ChatTutor.fromJson(json[r'tutor']),
      customer: ChatUser.fromJson(json[r'customer']),
      isArchived: mapValueOfType<bool>(json, r'is_archived'),
      created: mapDateTime(json, r'created', r''),
      unreadCount: mapValueOfType<int>(json, r'unread_count'),
      lastMessage: LastMessage.fromJson(json[r'last_message']),
      isTrialed: mapValueOfType<bool>(json, r'is_trialed'),
    );
  }
  return null;
}