fromJson static method
Returns a new ChatUser instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static ChatUser? 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 "ChatUser[id]" is missing from JSON.');
assert(json[r'id'] != null, 'Required key "ChatUser[id]" has a null value in JSON.');
assert(json.containsKey(r'name'), 'Required key "ChatUser[name]" is missing from JSON.');
assert(json[r'name'] != null, 'Required key "ChatUser[name]" has a null value in JSON.');
assert(json.containsKey(r'isBot'), 'Required key "ChatUser[isBot]" is missing from JSON.');
assert(json[r'isBot'] != null, 'Required key "ChatUser[isBot]" has a null value in JSON.');
assert(json.containsKey(r'isActive'), 'Required key "ChatUser[isActive]" is missing from JSON.');
assert(json[r'isActive'] != null, 'Required key "ChatUser[isActive]" has a null value in JSON.');
return true;
}());
return ChatUser(
id: mapValueOfType<String>(json, r'id')!,
provider: mapValueOfType<String>(json, r'provider'),
accountId: mapValueOfType<String>(json, r'accountId'),
name: mapValueOfType<String>(json, r'name')!,
realName: mapValueOfType<String>(json, r'realName'),
email: mapValueOfType<String>(json, r'email'),
avatar: mapValueOfType<String>(json, r'avatar'),
isBot: mapValueOfType<bool>(json, r'isBot')!,
isActive: mapValueOfType<bool>(json, r'isActive')!,
);
}
return null;
}