fromJson static method

InboxItem? fromJson(
  1. dynamic value
)

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

Implementation

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

    return InboxItem(
      id: mapValueOfType<String>(json, r'id')!,
      category: mapValueOfType<String>(json, r'category')!,
      title: mapValueOfType<String>(json, r'title'),
      snippet: mapValueOfType<String>(json, r'snippet'),
      source_: mapValueOfType<String>(json, r'source'),
      sourceId: mapValueOfType<String>(json, r'sourceId'),
      accountId: mapValueOfType<String>(json, r'accountId'),
      isRead: mapValueOfType<bool>(json, r'isRead'),
      isMention: mapValueOfType<bool>(json, r'isMention'),
      timestamp: mapDateTime(json, r'timestamp', r''),
      metadata: mapCastOfType<String, Object>(json, r'metadata') ?? const {},
    );
  }
  return null;
}