From 14f2401df776991414e6cddb26460f218895f029 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Mon, 11 Aug 2025 12:01:32 -0400 Subject: [PATCH] fix: don't set static default roles list (#3686) --- .../activity_planner/activity_plan_model.dart | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/pangea/activity_planner/activity_plan_model.dart b/lib/pangea/activity_planner/activity_plan_model.dart index 493b73fb5..3ce554b5d 100644 --- a/lib/pangea/activity_planner/activity_plan_model.dart +++ b/lib/pangea/activity_planner/activity_plan_model.dart @@ -13,7 +13,7 @@ class ActivityPlanModel { final String? imageURL; final DateTime? endAt; final Duration? duration; - final Map roles; + final Map? _roles; ActivityPlanModel({ required this.req, @@ -21,12 +21,26 @@ class ActivityPlanModel { required this.learningObjective, required this.instructions, required this.vocab, - required this.roles, + Map? roles, this.imageURL, this.endAt, this.duration, - }) : bookmarkId = - "${title.hashCode ^ learningObjective.hashCode ^ instructions.hashCode ^ imageURL.hashCode ^ vocab.map((v) => v.hashCode).reduce((a, b) => a ^ b)}"; + }) : bookmarkId = + "${title.hashCode ^ learningObjective.hashCode ^ instructions.hashCode ^ imageURL.hashCode ^ vocab.map((v) => v.hashCode).reduce((a, b) => a ^ b)}", + _roles = roles; + + Map get roles { + if (_roles != null) return _roles!; + final defaultRoles = {}; + for (int i = 0; i < req.numberOfParticipants; i++) { + defaultRoles['role_$i'] = ActivityRole( + id: 'role_$i', + name: 'Participant', + avatarUrl: null, + ); + } + return defaultRoles; + } ActivityPlanModel copyWith({ String? title, @@ -47,7 +61,7 @@ class ActivityPlanModel { imageURL: imageURL ?? this.imageURL, endAt: endAt ?? this.endAt, duration: duration ?? this.duration, - roles: roles ?? this.roles, + roles: roles ?? _roles, ); } @@ -55,7 +69,7 @@ class ActivityPlanModel { final req = ActivityPlanRequest.fromJson(json[ModelKey.activityPlanRequest]); - Map roles; + Map? roles; final roleContent = json['roles']; if (roleContent is Map) { roles = Map.from( @@ -66,15 +80,6 @@ class ActivityPlanModel { ), ), ); - } else { - roles = {}; - for (int i = 0; i < req.numberOfParticipants; i++) { - roles['role_$i'] = ActivityRole( - id: 'role_$i', - name: 'Participant', - avatarUrl: null, - ); - } } return ActivityPlanModel( @@ -115,7 +120,7 @@ class ActivityPlanModel { 'hours': duration?.inHours.remainder(24) ?? 0, 'minutes': duration?.inMinutes.remainder(60) ?? 0, }, - 'roles': roles.map( + 'roles': _roles?.map( (key, value) => MapEntry(key, value.toJson()), ), };