fromJson static method

FullUser? fromJson(
  1. dynamic value
)

Returns a new FullUser instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static FullUser? 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 "FullUser[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "FullUser[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return FullUser(
      id: mapValueOfType<int>(json, r'id'),
      email: mapValueOfType<String>(json, r'email')!,
      firstName: mapValueOfType<String>(json, r'first_name'),
      lastName: mapValueOfType<String>(json, r'last_name'),
      isActive: mapValueOfType<bool>(json, r'is_active'),
      isCustomer: mapValueOfType<bool>(json, r'is_customer'),
      isTutor: mapValueOfType<bool>(json, r'is_tutor'),
      lastLogin: mapDateTime(json, r'last_login', r''),
      latestPostcode: mapValueOfType<String>(json, r'latest_postcode'),
      phoneNumber: mapValueOfType<String>(json, r'phone_number'),
      isPhoneConfirmed: mapValueOfType<bool>(json, r'is_phone_confirmed'),
      photo: mapValueOfType<String>(json, r'photo'),
      ref: mapValueOfType<String>(json, r'ref'),
      reply: mapValueOfType<bool>(json, r'reply'),
      skypeAddress: mapValueOfType<String>(json, r'skype_address'),
      socialAuthMethod: SocialAuthMethodEnum.fromJson(json[r'social_auth_method']),
      agreedToTerms: mapValueOfType<bool>(json, r'agreed_to_terms'),
      called: mapValueOfType<bool>(json, r'called'),
      dateJoined: mapDateTime(json, r'date_joined', r''),
      dateOfBirth: mapDateTime(json, r'date_of_birth', r''),
      emailVerified: mapValueOfType<bool>(json, r'email_verified'),
      emailed: mapValueOfType<bool>(json, r'emailed'),
      gender: mapValueOfType<String>(json, r'gender'),
      hasCreditCard: mapValueOfType<bool>(json, r'has_credit_card'),
      isLive: mapValueOfType<bool>(json, r'is_live'),
      userTimezone: mapValueOfType<String>(json, r'user_timezone'),
      language: mapValueOfType<String>(json, r'language'),
      payViaOktopi: mapValueOfType<bool>(json, r'pay_via_oktopi'),
      stripeUserId: mapValueOfType<String>(json, r'stripe_user_id'),
    );
  }
  return null;
}