fromJson static method

Note? fromJson(
  1. dynamic value
)

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

Implementation

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

    return Note(
      id: mapValueOfType<String>(json, r'id')!,
      provider: mapValueOfType<String>(json, r'provider'),
      accountId: mapValueOfType<String>(json, r'accountId'),
      ownerUserId: mapValueOfType<String>(json, r'ownerUserId'),
      title: mapValueOfType<String>(json, r'title')!,
      content: mapValueOfType<String>(json, r'content')!,
      icon: mapValueOfType<String>(json, r'icon'),
      coverImage: mapValueOfType<String>(json, r'coverImage'),
      parentId: mapValueOfType<String>(json, r'parentId'),
      properties: mapCastOfType<String, Object>(json, r'properties') ?? const {},
      archived: mapValueOfType<bool>(json, r'archived')!,
      createdAt: mapDateTime(json, r'createdAt', r'')!,
      updatedAt: mapDateTime(json, r'updatedAt', r'')!,
      lastEditedBy: mapValueOfType<String>(json, r'lastEditedBy'),
    );
  }
  return null;
}