fromJson static method

LearnerInformationAPIData? fromJson(
  1. dynamic value
)

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

Implementation

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

    return LearnerInformationAPIData(
      username: mapValueOfType<String>(json, r'username')!,
      name: mapValueOfType<String>(json, r'name')!,
      email: mapValueOfType<String>(json, r'email')!,
      dateJoined: mapValueOfType<String>(json, r'date_joined')!,
      lastActivity: mapValueOfType<String>(json, r'last_activity')!,
      totalAssessments: mapValueOfType<int>(json, r'total_assessments'),
      totalTimeSpent: mapValueOfType<int>(json, r'total_time_spent'),
      totalVideos: mapValueOfType<int>(json, r'total_videos'),
      courseCompletions: mapValueOfType<int>(json, r'course_completions'),
      timeSpentOvertime: mapCastOfType<String, Object>(json, r'time_spent_overtime') ?? const {},
      continent: mapValueOfType<String>(json, r'continent'),
      continentCode: mapValueOfType<String>(json, r'continent_code'),
      country: mapValueOfType<String>(json, r'country'),
      countryCode: mapValueOfType<String>(json, r'country_code'),
      region: mapValueOfType<String>(json, r'region'),
      regionCode: mapValueOfType<String>(json, r'region_code'),
      location: mapValueOfType<String>(json, r'location'),
      city: mapValueOfType<String>(json, r'city'),
      browser: mapValueOfType<String>(json, r'browser'),
      operatingSystem: mapValueOfType<String>(json, r'operating_system'),
      resolution: mapValueOfType<String>(json, r'resolution'),
    );
  }
  return null;
}