From 2b9ac14d6e726526ef5cd474590f55e1ca58a24a Mon Sep 17 00:00:00 2001 From: checkedear <271323618+checkedear@users.noreply.github.com> Date: Thu, 11 Jun 2026 11:50:12 +0200 Subject: [PATCH] fix: active lesson on homepage --- firka/lib/ui/phone/widgets/lesson_slider.dart | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/firka/lib/ui/phone/widgets/lesson_slider.dart b/firka/lib/ui/phone/widgets/lesson_slider.dart index bf215c2..a50a9d5 100644 --- a/firka/lib/ui/phone/widgets/lesson_slider.dart +++ b/firka/lib/ui/phone/widgets/lesson_slider.dart @@ -49,15 +49,20 @@ class _LessonSliderState extends State { var lessons = widget.lessons.keys.toList(); - var currentLesson = widget.lessons.keys.firstWhereOrNull( - (lesson) => now.isBefore(lesson.end), - ); + Lesson? currentLesson; + int tmpIndex; + if (now.isBefore(lessons.first.start)) { + tmpIndex = 0; + } else { + (int, Lesson)? currentIndex = lessons.indexed.firstWhereOrNull( + (e) => now.isBefore(e.$2.end), + ); - int tmpIndex = lessons.isEmpty || now.isBefore(lessons.first.start) - ? 0 - : currentLesson == null - ? lessons.length + 1 - : lessons.indexOf(currentLesson) + 1; + tmpIndex = (currentIndex?.$1 ?? lessons.length) + 1; + if (currentIndex != null) { + currentLesson = currentIndex.$2; + } + } if (activeLessonIndex == null || tmpIndex != activeLessonIndex) { activeLessonIndex = tmpIndex;