fromJson static method

TutorProfileDisplay? fromJson(
  1. dynamic value
)

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

Implementation

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

    return TutorProfileDisplay(
      id: mapValueOfType<int>(json, r'id'),
      user: UserRetrival.fromJson(json[r'user'])!,
      tutorProfileId: mapValueOfType<int>(json, r'tutor_profile_id'),
      experience: mapValueOfType<String>(json, r'experience'),
      experienceYears: mapValueOfType<int>(json, r'experience_years'),
      address: mapValueOfType<String>(json, r'address'),
      dbsNumber: mapValueOfType<String>(json, r'dbs_number'),
      video: mapValueOfType<String>(json, r'video'),
      videoLink: mapValueOfType<String>(json, r'video_link'),
      inPersonTutoring: mapValueOfType<bool>(json, r'in_person_tutoring'),
      onlineTutoring: mapValueOfType<bool>(json, r'online_tutoring'),
      personalityType: mapValueOfType<String>(json, r'personality_type'),
      profilePhotoRejected: mapValueOfType<bool>(json, r'profile_photo_rejected'),
      numReviews: mapValueOfType<int>(json, r'num_reviews') ?? 0,
      subjects: TutorSubject.listFromJson(json[r'subjects']),
      selectedSubject: TutorSubject.fromJson(json[r'selected_subject']),
      photo: mapValueOfType<String>(json, r'photo')!,
      isDbsChecked: mapValueOfType<bool>(json, r'is_dbs_checked'),
      isDbsCompleted: mapValueOfType<bool>(json, r'is_dbs_completed'),
      qualifications: TutorQualification.listFromJson(json[r'qualifications']),
      hasSkype: mapValueOfType<bool>(json, r'has_skype'),
      metInPerson: mapValueOfType<bool>(json, r'met_in_person'),
      coverageNames: json[r'coverage_names'] is Iterable
          ? (json[r'coverage_names'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      rating: mapValueOfType<int>(json, r'rating') ?? 0,
      responseTimeDisplay: mapValueOfType<String>(json, r'response_time_display'),
      postcode: mapValueOfType<String>(json, r'postcode'),
      slug: mapValueOfType<String>(json, r'slug'),
      isSuperTutor: mapValueOfType<bool>(json, r'is_super_tutor'),
      numFiveStarReviews: mapValueOfType<int>(json, r'num_five_star_reviews'),
      numExcellentReviews: mapValueOfType<int>(json, r'num_excellent_reviews'),
      numProfileViews: mapValueOfType<int>(json, r'num_profile_views'),
      tagline: mapValueOfType<String>(json, r'tagline'),
      badgeHeader: mapValueOfType<String>(json, r'badge_header')!,
      hasNumberOfViewsBadge: mapValueOfType<String>(json, r'has_number_of_views_badge'),
      isLive: mapValueOfType<bool>(json, r'is_live'),
      completedSections: json[r'completed_sections'] is Iterable
          ? (json[r'completed_sections'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      incompleteSections: json[r'incomplete_sections'] is Iterable
          ? (json[r'incomplete_sections'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      profileSubmitted: mapValueOfType<bool>(json, r'profile_submitted'),
      isFeatured: mapValueOfType<bool>(json, r'is_featured'),
      enableTrial: mapValueOfType<bool>(json, r'enable_trial'),
      enableInstant: mapValueOfType<bool>(json, r'enable_instant'),
      school: mapValueOfType<int>(json, r'school'),
      schoolName: mapValueOfType<String>(json, r'school_name') ?? '',
      country: Country.fromJson(json[r'country']),
      hasStripeAccount: mapValueOfType<bool>(json, r'has_stripe_account'),
      availability: TutorAvailability.listFromJson(json[r'availability']),
      timeOff: TutorTimeOff.listFromJson(json[r'time_off']),
      userTimezone: mapValueOfType<String>(json, r'user_timezone')!,
      isTrialed: mapValueOfType<bool>(json, r'is_trialed'),
    );
  }
  return null;
}