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'),
object: UserObjectEnum.fromJson(json[r'object']),
externalId: mapValueOfType<String>(json, r'external_id'),
primaryEmailAddressId:
mapValueOfType<String>(json, r'primary_email_address_id'),
primaryPhoneNumberId:
mapValueOfType<String>(json, r'primary_phone_number_id'),
primaryWeb3WalletId:
mapValueOfType<String>(json, r'primary_web3_wallet_id'),
username: mapValueOfType<String>(json, r'username'),
firstName: mapValueOfType<String>(json, r'first_name'),
lastName: mapValueOfType<String>(json, r'last_name'),
profileImageUrl: mapValueOfType<String>(json, r'profile_image_url'),
imageUrl: mapValueOfType<String>(json, r'image_url'),
hasImage: mapValueOfType<bool>(json, r'has_image'),
publicMetadata:
mapCastOfType<String, Object>(json, r'public_metadata') ?? const {},
privateMetadata:
mapCastOfType<String, Object>(json, r'private_metadata') ??
const {},
unsafeMetadata:
mapCastOfType<String, Object>(json, r'unsafe_metadata') ?? const {},
emailAddresses: EmailAddress.listFromJson(json[r'email_addresses']),
phoneNumbers: PhoneNumber.listFromJson(json[r'phone_numbers']),
web3Wallets: Web3Wallet.listFromJson(json[r'web3_wallets']),
passkeys: SchemasPasskey.listFromJson(json[r'passkeys']),
passwordEnabled: mapValueOfType<bool>(json, r'password_enabled'),
twoFactorEnabled: mapValueOfType<bool>(json, r'two_factor_enabled'),
totpEnabled: mapValueOfType<bool>(json, r'totp_enabled'),
backupCodeEnabled: mapValueOfType<bool>(json, r'backup_code_enabled'),
mfaEnabledAt: mapValueOfType<int>(json, r'mfa_enabled_at'),
mfaDisabledAt: mapValueOfType<int>(json, r'mfa_disabled_at'),
externalAccounts: (json[r'external_accounts'] as List? ?? []),
samlAccounts: SAMLAccount.listFromJson(json[r'saml_accounts']),
lastSignInAt: mapValueOfType<int>(json, r'last_sign_in_at'),
banned: mapValueOfType<bool>(json, r'banned'),
locked: mapValueOfType<bool>(json, r'locked'),
lockoutExpiresInSeconds:
mapValueOfType<int>(json, r'lockout_expires_in_seconds'),
verificationAttemptsRemaining:
mapValueOfType<int>(json, r'verification_attempts_remaining'),
updatedAt: mapValueOfType<int>(json, r'updated_at'),
createdAt: mapValueOfType<int>(json, r'created_at'),
deleteSelfEnabled: mapValueOfType<bool>(json, r'delete_self_enabled'),
createOrganizationEnabled:
mapValueOfType<bool>(json, r'create_organization_enabled'),
createOrganizationsLimit:
mapValueOfType<int>(json, r'create_organizations_limit'),
lastActiveAt: mapValueOfType<int>(json, r'last_active_at'),
legalAcceptedAt: mapValueOfType<int>(json, r'legal_accepted_at'),
);
}
return null;
}