fromJson static method
User?
fromJson(
- dynamic value
)
Returns a new User instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static User? 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 "User[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "User[$key]" has a null value in JSON.');
});
return true;
}());
return User(
avgResponseTime: mapValueOfType<int>(json, r'avg_response_time'),
banExpires: mapDateTime(json, r'ban_expires', r''),
banned: mapValueOfType<bool>(json, r'banned')!,
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''),
id: mapValueOfType<String>(json, r'id')!,
invisible: mapValueOfType<bool>(json, r'invisible'),
language: mapValueOfType<String>(json, r'language'),
lastActive: mapDateTime(json, r'last_active', r''),
lastEngagedAt: mapDateTime(json, r'last_engaged_at', r''),
online: mapValueOfType<bool>(json, r'online')!,
privacySettings: PrivacySettings.fromJson(json[r'privacy_settings']),
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 [],
teamsRole: mapCastOfType<String, String>(json, r'teams_role')!,
updatedAt: mapDateTime(json, r'updated_at', r''),
);
}
return null;
}