fromJson static method
Returns a new ChannelResponse instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static ChannelResponse? 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 "ChannelResponse[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "ChannelResponse[$key]" has a null value in JSON.');
});
return true;
}());
return ChannelResponse(
autoTranslationEnabled: mapValueOfType<bool>(json, r'auto_translation_enabled'),
autoTranslationLanguage: mapValueOfType<String>(json, r'auto_translation_language'),
blocked: mapValueOfType<bool>(json, r'blocked'),
cid: mapValueOfType<String>(json, r'cid')!,
config: ChannelConfigWithInfo.fromJson(json[r'config']),
cooldown: mapValueOfType<int>(json, r'cooldown'),
createdAt: mapDateTime(json, r'created_at', r'')!,
createdBy: UserObject.fromJson(json[r'created_by']),
custom: mapCastOfType<String, Object>(json, r'custom')!,
deletedAt: mapDateTime(json, r'deleted_at', r''),
disabled: mapValueOfType<bool>(json, r'disabled')!,
frozen: mapValueOfType<bool>(json, r'frozen')!,
hidden: mapValueOfType<bool>(json, r'hidden'),
hideMessagesBefore: mapDateTime(json, r'hide_messages_before', r''),
id: mapValueOfType<String>(json, r'id')!,
lastMessageAt: mapDateTime(json, r'last_message_at', r''),
memberCount: mapValueOfType<int>(json, r'member_count'),
members: ChannelMember.listFromJson(json[r'members']),
muteExpiresAt: mapDateTime(json, r'mute_expires_at', r''),
muted: mapValueOfType<bool>(json, r'muted'),
ownCapabilities: json[r'own_capabilities'] is Iterable
? (json[r'own_capabilities'] as Iterable).cast<String>().toList(growable: false)
: const [],
team: mapValueOfType<String>(json, r'team'),
truncatedAt: mapDateTime(json, r'truncated_at', r''),
truncatedBy: UserObject.fromJson(json[r'truncated_by']),
type: mapValueOfType<String>(json, r'type')!,
updatedAt: mapDateTime(json, r'updated_at', r'')!,
);
}
return null;
}