fromJson static method

OwnUserResponse? fromJson(
  1. dynamic value
)

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

Implementation

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

    return OwnUserResponse(
      banned: mapValueOfType<bool>(json, r'banned')!,
      blockedUserIds: json[r'blocked_user_ids'] is Iterable
          ? (json[r'blocked_user_ids'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      channelMutes: ChannelMute.listFromJson(json[r'channel_mutes']),
      createdAt: mapDateTime(json, r'created_at', r'')!,
      custom: mapCastOfType<String, Object>(json, r'custom')!,
      deactivatedAt: mapDateTime(json, r'deactivated_at', r''),
      deletedAt: mapDateTime(json, r'deleted_at', r''),
      devices: Device.listFromJson(json[r'devices']),
      id: mapValueOfType<String>(json, r'id')!,
      image: mapValueOfType<String>(json, r'image'),
      invisible: mapValueOfType<bool>(json, r'invisible')!,
      language: mapValueOfType<String>(json, r'language')!,
      lastActive: mapDateTime(json, r'last_active', r''),
      latestHiddenChannels: json[r'latest_hidden_channels'] is Iterable
          ? (json[r'latest_hidden_channels'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      mutes: UserMuteResponse.listFromJson(json[r'mutes']),
      name: mapValueOfType<String>(json, r'name'),
      online: mapValueOfType<bool>(json, r'online')!,
      privacySettings: PrivacySettingsResponse.fromJson(json[r'privacy_settings']),
      pushNotifications: PushNotificationSettingsResponse.fromJson(json[r'push_notifications']),
      revokeTokensIssuedBefore: mapDateTime(json, r'revoke_tokens_issued_before', r''),
      role: mapValueOfType<String>(json, r'role')!,
      teams: json[r'teams'] is Iterable
          ? (json[r'teams'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      totalUnreadCount: mapValueOfType<int>(json, r'total_unread_count')!,
      unreadChannels: mapValueOfType<int>(json, r'unread_channels')!,
      unreadCount: mapValueOfType<int>(json, r'unread_count')!,
      unreadThreads: mapValueOfType<int>(json, r'unread_threads')!,
      updatedAt: mapDateTime(json, r'updated_at', r'')!,
    );
  }
  return null;
}