fromJson static method
Returns a new Channel instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Channel? 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 "Channel[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "Channel[$key]" has a null value in JSON.');
});
return true;
}());
return Channel(
autoTranslationEnabled: mapValueOfType<bool>(json, r'auto_translation_enabled'),
autoTranslationLanguage: mapValueOfType<String>(json, r'auto_translation_language')!,
cid: mapValueOfType<String>(json, r'cid')!,
config: ChannelConfig.fromJson(json[r'config']),
configOverrides: ChannelConfig.fromJson(json[r'config_overrides']),
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')!,
id: mapValueOfType<String>(json, r'id')!,
invites: ChannelMember.listFromJson(json[r'invites']),
lastMessageAt: mapDateTime(json, r'last_message_at', r''),
memberCount: mapValueOfType<int>(json, r'member_count'),
members: ChannelMember.listFromJson(json[r'members']),
team: mapValueOfType<String>(json, r'team'),
truncatedBy: UserObject.fromJson(json[r'truncated_by']),
type: mapValueOfType<String>(json, r'type')!,
updatedAt: mapDateTime(json, r'updated_at', r'')!,
);
}
return null;
}