fromJson static method

PublicCommentBase? fromJson(
  1. dynamic value
)

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

Implementation

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

    return PublicCommentBase(
      id: mapValueOfType<String>(json, r'_id')!,
      userId: mapValueOfType<String>(json, r'userId'),
      commenterName: mapValueOfType<String>(json, r'commenterName')!,
      commenterLink: mapValueOfType<String>(json, r'commenterLink'),
      commentHTML: mapValueOfType<String>(json, r'commentHTML')!,
      parentId: mapValueOfType<String>(json, r'parentId'),
      date: mapDateTime(json, r'date', r''),
      votes: mapValueOfType<int>(json, r'votes'),
      votesUp: mapValueOfType<int>(json, r'votesUp'),
      votesDown: mapValueOfType<int>(json, r'votesDown'),
      verified: mapValueOfType<bool>(json, r'verified')!,
      avatarSrc: mapValueOfType<String>(json, r'avatarSrc'),
      hasImages: mapValueOfType<bool>(json, r'hasImages'),
      isByAdmin: mapValueOfType<bool>(json, r'isByAdmin'),
      isByModerator: mapValueOfType<bool>(json, r'isByModerator'),
      isPinned: mapValueOfType<bool>(json, r'isPinned'),
      isLocked: mapValueOfType<bool>(json, r'isLocked'),
      displayLabel: mapValueOfType<String>(json, r'displayLabel'),
      rating: mapValueOfType<double>(json, r'rating'),
      badges: CommentUserBadgeInfo.listFromJson(json[r'badges']),
      viewCount: mapValueOfType<int>(json, r'viewCount'),
      isDeleted: mapValueOfType<bool>(json, r'isDeleted'),
      isDeletedUser: mapValueOfType<bool>(json, r'isDeletedUser'),
      isSpam: mapValueOfType<bool>(json, r'isSpam'),
      anonUserId: mapValueOfType<String>(json, r'anonUserId'),
      feedbackIds: json[r'feedbackIds'] is Iterable
          ? (json[r'feedbackIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      requiresVerification: mapValueOfType<bool>(json, r'requiresVerification'),
      editKey: mapValueOfType<String>(json, r'editKey'),
      approved: mapValueOfType<bool>(json, r'approved'),
    );
  }
  return null;
}