fromJson static method

TutorCard? fromJson(
  1. dynamic value
)

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

Implementation

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

    return TutorCard(
      id: mapValueOfType<int>(json, r'id')!,
      photo: mapValueOfType<String>(json, r'photo'),
      tutorProfileId: mapValueOfType<int>(json, r'tutor_profile_id')!,
      selectedSubject: TutorSubject.fromJson(json[r'selected_subject']),
      experienceYears: mapValueOfType<int>(json, r'experience_years'),
      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') ?? false,
      hasWhiteboardAccess: mapValueOfType<bool>(json, r'has_whiteboard_access'),
      tagline: mapValueOfType<String>(json, r'tagline'),
      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'),
      totalBookings: mapValueOfType<int>(json, r'total_bookings') ?? 0,
      isDbsChecked: mapValueOfType<bool>(json, r'is_dbs_checked') ?? false,
      onlineLastMonth: mapValueOfType<bool>(json, r'online_last_month') ?? false,
      lastLogin: mapDateTime(json, r'last_login', r''),
      school: mapValueOfType<int>(json, r'school'),
      schoolName: mapValueOfType<String>(json, r'school_name') ?? '',
      isTrialed: mapValueOfType<bool>(json, r'is_trialed'),
      userTimezone: mapValueOfType<String>(json, r'user_timezone') ?? '',
      subjects: TutorCardSubject.listFromJson(json[r'subjects']),
      country: mapValueOfType<String>(json, r'country'),
    );
  }
  return null;
}