Study.fromJson constructor

Study.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Study.fromJson(Map<String, dynamic> json) {
  final study = _$StudyFromJson(json);

  final List? repo = json['repo'] as List?;
  if (repo != null && repo.isNotEmpty) {
    study.repo =
        Repo.fromJson((json['repo'] as List)[0] as Map<String, dynamic>);
  }

  final List? invites = json['study_invite'] as List?;
  if (invites != null) {
    study.invites = invites
        .map((json) => StudyInvite.fromJson(json as Map<String, dynamic>))
        .toList();
  }

  final List? participants = json['study_subject'] as List?;
  if (participants != null) {
    study.participants = participants
        .map((json) => StudySubject.fromJson(json as Map<String, dynamic>))
        .toList();
  }

  List? participantsProgress = json['study_progress'] as List?;
  participantsProgress = json['study_progress_export'] as List?;
  participantsProgress ??= json['subject_progress'] as List?;
  if (participantsProgress != null) {
    study.participantsProgress = participantsProgress
        .map((json) => SubjectProgress.fromJson(json as Map<String, dynamic>))
        .toList();
  }

  final int? participantCount = json['study_participant_count'] as int?;
  if (participantCount != null) {
    study.participantCount = participantCount;
  }

  final int? endedCount = json['study_ended_count'] as int?;
  if (endedCount != null) {
    study.endedCount = endedCount;
  }

  final int? activeSubjectCount = json['active_subject_count'] as int?;
  if (activeSubjectCount != null) {
    study.activeSubjectCount = activeSubjectCount;
  }

  final List? missedDays = json['study_missed_days'] as List?;
  if (missedDays != null) {
    study.missedDays = List<int>.from(json['study_missed_days'] as List);
  }

  final String? createdAt = json['created_at'] as String?;
  if (createdAt != null && createdAt.isNotEmpty) {
    study.createdAt = DateTime.parse(createdAt);
  }

  return study;
}