CourseProgress.fromJson constructor

CourseProgress.fromJson(
  1. String courseId,
  2. Map<String, dynamic> json
)

Implementation

factory CourseProgress.fromJson(String courseId, Map<String, dynamic> json) {
  final records = <String, ExerciseRecord>{};
  final stored = json['records'];
  if (stored is Map) {
    stored.forEach((key, value) {
      if (key is String && value is Map) {
        records[key] = ExerciseRecord.fromJson(value.cast<String, dynamic>());
      }
    });
  }
  final doneLessons = <String>{};
  final storedDone = json['doneLessons'];
  if (storedDone is List) {
    for (final id in storedDone) {
      if (id is String) doneLessons.add(id);
    }
  }
  final last = json['lastLessonId'];
  return CourseProgress(
    courseId: courseId,
    records: records,
    doneLessons: doneLessons,
    lastLessonId: last is String && last.isNotEmpty ? last : null,
  );
}