From 29543ef4a32554c6c0bb82c22b27f2e104ee3b96 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Tue, 9 Sep 2025 10:08:32 -0400 Subject: [PATCH] fix: always initialize course info after fetching (#3907) --- .../activity_finished_status_message.dart | 5 ----- lib/pangea/course_plans/course_plan_builder.dart | 6 +----- lib/pangea/course_plans/course_plans_repo.dart | 5 ++++- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/pangea/activity_sessions/activity_session_chat/activity_finished_status_message.dart b/lib/pangea/activity_sessions/activity_session_chat/activity_finished_status_message.dart index 5f240f532..52e53ea6c 100644 --- a/lib/pangea/activity_sessions/activity_session_chat/activity_finished_status_message.dart +++ b/lib/pangea/activity_sessions/activity_session_chat/activity_finished_status_message.dart @@ -56,11 +56,6 @@ class ActivityFinishedStatusMessage extends StatelessWidget { courseParent!.coursePlan!.uuid, ); - if (coursePlan == null) { - throw L10n.of(context).noCourseFound; - } - - await coursePlan.init(); final activityId = controller.room.activityPlan!.activityId; final topicId = coursePlan.topicID(activityId); if (topicId == null) { diff --git a/lib/pangea/course_plans/course_plan_builder.dart b/lib/pangea/course_plans/course_plan_builder.dart index f44ed9815..ecf4d0a66 100644 --- a/lib/pangea/course_plans/course_plan_builder.dart +++ b/lib/pangea/course_plans/course_plan_builder.dart @@ -61,14 +61,10 @@ class CoursePlanController extends State { }); course = await CoursePlansRepo.get(widget.courseId!); - if (course == null) { - widget.onNotFound?.call(); - } else { - await course!.init(); - } widget.onLoaded?.call(course!); } catch (e) { + widget.onNotFound?.call(); error = e; } finally { setState(() { diff --git a/lib/pangea/course_plans/course_plans_repo.dart b/lib/pangea/course_plans/course_plans_repo.dart index f8aee147c..1ad7f6f72 100644 --- a/lib/pangea/course_plans/course_plans_repo.dart +++ b/lib/pangea/course_plans/course_plans_repo.dart @@ -91,7 +91,7 @@ class CoursePlansRepo { await _courseStorage.write(_searchKey(filter), jsonList); } - static Future get(String id) async { + static Future get(String id) async { final cached = _getCached(id); if (cached != null) { return cached; @@ -113,6 +113,7 @@ class CoursePlansRepo { final coursePlan = cmsCoursePlan.toCoursePlanModel(); await _setCached(coursePlan); + await coursePlan.init(); completer.complete(coursePlan); return coursePlan; } catch (e) { @@ -194,6 +195,8 @@ class CoursePlansRepo { coursePlans, ); + final futures = coursePlans.map((c) => c.init()); + await Future.wait(futures); return coursePlans; } }