fromJson static method

ChannelMember? fromJson(
  1. dynamic value
)

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

Implementation

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

    return ChannelMember(
      banExpires: mapDateTime(json, r'ban_expires', r''),
      banned: mapValueOfType<bool>(json, r'banned')!,
      channelRole: mapValueOfType<String>(json, r'channel_role')!,
      createdAt: mapDateTime(json, r'created_at', r'')!,
      custom: mapCastOfType<String, Object>(json, r'custom')!,
      deletedAt: mapDateTime(json, r'deleted_at', r''),
      inviteAcceptedAt: mapDateTime(json, r'invite_accepted_at', r''),
      inviteRejectedAt: mapDateTime(json, r'invite_rejected_at', r''),
      invited: mapValueOfType<bool>(json, r'invited'),
      isModerator: mapValueOfType<bool>(json, r'is_moderator'),
      notificationsMuted: mapValueOfType<bool>(json, r'notifications_muted')!,
      shadowBanned: mapValueOfType<bool>(json, r'shadow_banned')!,
      status: mapValueOfType<String>(json, r'status'),
      updatedAt: mapDateTime(json, r'updated_at', r'')!,
      user: UserObject.fromJson(json[r'user']),
      userId: mapValueOfType<String>(json, r'user_id'),
    );
  }
  return null;
}