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(
id: mapValueOfType<String>(json, r'id')!,
name: mapValueOfType<String>(json, r'name')!,
email: mapValueOfType<String>(json, r'email')!,
emailVerified: mapValueOfType<bool>(json, r'emailVerified'),
image: mapValueOfType<String>(json, r'image'),
blocked: mapValueOfType<bool>(json, r'blocked')!,
authProviderUserId: mapValueOfType<String>(json, r'authProviderUserId'),
locale: mapValueOfType<String>(json, r'locale'),
scimExternalId: mapValueOfType<String>(json, r'scimExternalId'),
metadata: UserMetadata.fromJson(json[r'metadata']),
sessionVersion: mapValueOfType<int>(json, r'sessionVersion')!,
twoFactorEnabled: mapValueOfType<bool>(json, r'twoFactorEnabled'),
twoFactorSecret: mapValueOfType<String>(json, r'twoFactorSecret'),
twoFactorBackupCodes: mapValueOfType<String>(json, r'twoFactorBackupCodes'),
isPlatformAdmin: mapValueOfType<bool>(json, r'isPlatformAdmin')!,
onboardingState: UserMetadata.fromJson(json[r'onboardingState']),
createdAt: mapDateTime(json, r'createdAt', r'')!,
updatedAt: mapValueOfType<String>(json, r'updatedAt'),
lastLoginAt: mapValueOfType<String>(json, r'lastLoginAt'),
failedLoginAttempts: mapValueOfType<int>(json, r'failedLoginAttempts')!,
lockedUntil: mapValueOfType<String>(json, r'lockedUntil'),
deletedAt: mapValueOfType<String>(json, r'deletedAt'),
deletedBy: mapValueOfType<String>(json, r'deletedBy'),
);
}
return null;
}