fromJson static method

IndexTutorCard? fromJson(
  1. dynamic value
)

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

Implementation

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

    return IndexTutorCard(
      id: mapValueOfType<int>(json, r'id')!,
      photo: mapValueOfType<String>(json, r'photo')!,
      tutorProfileId: mapValueOfType<int>(json, r'tutor_profile_id')!,
      experienceYears: mapValueOfType<int>(json, r'experience_years'),
      totalBookings: mapValueOfType<String>(json, r'total_bookings'),
      numReviews: mapValueOfType<int>(json, r'num_reviews') ?? 0,
      name: mapValueOfType<String>(json, r'name')!,
      experience: mapValueOfType<String>(json, r'experience'),
      photoCard: mapValueOfType<String>(json, r'photo_card')!,
      photoThumbnail: mapValueOfType<String>(json, r'photo_thumbnail')!,
      hasSkype: mapValueOfType<bool>(json, r'has_skype'),
      responseTimeDisplay: mapValueOfType<String>(json, r'response_time_display'),
      rating: mapValueOfType<int>(json, r'rating') ?? 0,
      isFeatured: mapValueOfType<bool>(json, r'is_featured'),
      slug: mapValueOfType<String>(json, r'slug'),
      isSuperTutor: mapValueOfType<bool>(json, r'is_super_tutor'),
      hasWhiteboardAccess: mapValueOfType<bool>(json, r'has_whiteboard_access'),
      tagline: mapValueOfType<String>(json, r'tagline'),
      qualifications: TutorQualification.listFromJson(json[r'qualifications']),
      numProfileViews: mapValueOfType<int>(json, r'num_profile_views'),
      numFiveStarReviews: mapValueOfType<int>(json, r'num_five_star_reviews'),
      numExcellentReviews: mapValueOfType<int>(json, r'num_excellent_reviews'),
      onlineTutoring: mapValueOfType<bool>(json, r'online_tutoring'),
      inPersonTutoring: mapValueOfType<bool>(json, r'in_person_tutoring'),
      selectedSubject: TutorSubject.fromJson(json[r'selected_subject']),
      onlineLastMonth: mapValueOfType<bool>(json, r'online_last_month') ?? false,
      lastLogin: mapDateTime(json, r'last_login', r''),
      school: mapValueOfType<int>(json, r'school'),
      isDbsChecked: mapValueOfType<String>(json, r'is_dbs_checked'),
      isQualifiedTutor: mapValueOfType<String>(json, r'is_qualified_tutor'),
      schoolName: mapValueOfType<String>(json, r'school_name') ?? '',
      userTimezone: mapValueOfType<String>(json, r'user_timezone')!,
      subjects: mapValueOfType<String>(json, r'subjects'),
    );
  }
  return null;
}