From e06d2168c071feee2cf09b116f091d31e0cde328 Mon Sep 17 00:00:00 2001 From: checkedear <271323618+checkedear@users.noreply.github.com> Date: Wed, 29 Apr 2026 15:12:54 +0200 Subject: [PATCH] fix: display current lesson on homepage --- firka/lib/ui/phone/pages/home/home_main.dart | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/firka/lib/ui/phone/pages/home/home_main.dart b/firka/lib/ui/phone/pages/home/home_main.dart index 3f1c133..fc261e3 100644 --- a/firka/lib/ui/phone/pages/home/home_main.dart +++ b/firka/lib/ui/phone/pages/home/home_main.dart @@ -38,9 +38,9 @@ class _HomeMainScreen extends FirkaState { _HomeMainScreen(); DateTime now = timeNow(); - int swipeBack = 0; - int activeLessonIndex = 0; - int centeredPageIndex = 0; + int? swipeBack; + int? activeLessonIndex; + int? centeredPageIndex; List? lessons; List? noticeBoard; List? infoBoard; @@ -185,7 +185,7 @@ class _HomeMainScreen extends FirkaState { })(); timer = Timer.periodic(Duration(seconds: 1), (timer) async { - if (swipeBack > 0) swipeBack -= 1; + if (swipeBack != null) swipeBack = swipeBack! - 1; if (!mounted) return; setState(() { now = timeNow(); @@ -262,13 +262,15 @@ class _HomeMainScreen extends FirkaState { ? lessons!.length + 1 : lessons!.indexOf(currentLesson) + 1; - if (tmpIndex != activeLessonIndex) { + if (activeLessonIndex == null || tmpIndex != activeLessonIndex) { activeLessonIndex = tmpIndex; swipeBack = 0; } + centeredPageIndex ??= activeLessonIndex!; + if (controller.ready && swipeBack == 0) { - controller.animateToPage(activeLessonIndex); + controller.animateToPage(activeLessonIndex!); } int testsTomorrow = testItems @@ -385,22 +387,20 @@ class _HomeMainScreen extends FirkaState { ], carouselController: controller, options: CarouselOptions( - initialPage: activeLessonIndex, + initialPage: activeLessonIndex!, height: 106, viewportFraction: 346 / 376, enableInfiniteScroll: false, onPageChanged: (index, reason) { centeredPageIndex = index; if (index == activeLessonIndex) { - swipeBack = -1; + swipeBack = null; } else if (reason == CarouselPageChangedReason.manual) { swipeBack = 5; } else { return; } - setState(() { - centeredPageIndex = index; - }); + setState(() {}); }, ), ),