Problem
When a user switches between lessons in a course, the lesson details panel shows a loading skeleton every time, even if the lesson was previously loaded. This creates a poor UX with constant flickering and delays.
Current Behavior
In CourseCubit.selectLesson():
- Sets isLessonDetailsLoading = true (shows skeleton)
- Calls _lessonsRepository.getLesson(lessonId) (always network call)
- Waits for response
- Sets isLessonDetailsLoading = false
This happens every time the user clicks on a lesson, even if they just viewed it.
Expected Behavior
- Once a lesson is loaded, it should be cached in memory for the session
- Switching back to a previously viewed lesson should be instant (no loading state)
- Cache is per-course and per-session (cleared when leaving the course)
Proposed Solution
Add an in-memory cache in CourseCubit:
dart // Cache for loaded lessons: lessonId -> Lesson static final _lessonsCache = <String, Lesson>{};
Modify selectLesson() to check cache first:
`dart
Future selectLesson(String lessonId) async {
// Check cache first
final cachedLesson = _lessonsCache[lessonId];
if (cachedLesson != null) {
emit(state.copyWith(selectedLesson: cachedLesson));
// Optionally refresh in background
_refreshLessonInBackground(lessonId);
return;
}
// Show loading only if not in cache
emit(state.copyWith(isLessonDetailsLoading: true));
// ... existing loading logic
}
`
Additional Context
The lessons list already has caching (_lessonsCache for List), but the lesson details don't.
Acceptance Criteria
Files to Modify
- �pps/condor_code_app/lib/ui/screens/course/course_cubit/course_cubit.dart
- �pps/condor_code_app/lib/ui/screens/course/course_cubit/course_state.dart (maybe, for tasks cache)
Problem
When a user switches between lessons in a course, the lesson details panel shows a loading skeleton every time, even if the lesson was previously loaded. This creates a poor UX with constant flickering and delays.
Current Behavior
In CourseCubit.selectLesson():
This happens every time the user clicks on a lesson, even if they just viewed it.
Expected Behavior
Proposed Solution
Add an in-memory cache in CourseCubit:
dart // Cache for loaded lessons: lessonId -> Lesson static final _lessonsCache = <String, Lesson>{};Modify selectLesson() to check cache first:
`dart
Future selectLesson(String lessonId) async {
// Check cache first
final cachedLesson = _lessonsCache[lessonId];
if (cachedLesson != null) {
emit(state.copyWith(selectedLesson: cachedLesson));
// Optionally refresh in background
_refreshLessonInBackground(lessonId);
return;
}
// Show loading only if not in cache
emit(state.copyWith(isLessonDetailsLoading: true));
// ... existing loading logic
}
`
Additional Context
The lessons list already has caching (_lessonsCache for List), but the lesson details don't.
Acceptance Criteria
Files to Modify