From 8112d43357a096edbd7aa863ba20a969ed0ae790 Mon Sep 17 00:00:00 2001 From: b3ni15 Date: Wed, 3 Sep 2025 22:52:11 +0200 Subject: [PATCH] Update lesson handling logic in HomeTimetableScreen to manage active lesson index based on today's lessons --- .../ui/phone/pages/home/home_timetable.dart | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/firka/lib/ui/phone/pages/home/home_timetable.dart b/firka/lib/ui/phone/pages/home/home_timetable.dart index 99e101a..cc96bed 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable.dart @@ -87,7 +87,26 @@ class _HomeTimetableScreen extends State { d.day == todayMid.day); if (idx >= 0) { - active = idx; + final todaysLessons = lessons?.where((lesson) => + lesson.start.isAfter(todayMid) && + lesson.end.isBefore(todayMid.add(Duration(hours: 23, minutes: 59)))); + + if (todaysLessons != null && todaysLessons.isNotEmpty) { + final lastLessonToday = todaysLessons.reduce((a, b) => a.end.isAfter(b.end) ? a : b); + + if (now.isAfter(lastLessonToday.end)) { + int nextIdx = idx + 1; + if (nextIdx < dates.length) { + active = nextIdx; + } else { + active = idx; + } + } else { + active = idx; + } + } else { + active = idx; + } } else if (now.isAfter(dates.last)) { active = dates.length - 1; } else {