fix: display current lesson on homepage

This commit is contained in:
checkedear
2026-04-29 15:12:54 +02:00
parent 91603923bc
commit e06d2168c0

View File

@@ -38,9 +38,9 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
_HomeMainScreen(); _HomeMainScreen();
DateTime now = timeNow(); DateTime now = timeNow();
int swipeBack = 0; int? swipeBack;
int activeLessonIndex = 0; int? activeLessonIndex;
int centeredPageIndex = 0; int? centeredPageIndex;
List<Lesson>? lessons; List<Lesson>? lessons;
List<NoticeBoardItem>? noticeBoard; List<NoticeBoardItem>? noticeBoard;
List<InfoBoardItem>? infoBoard; List<InfoBoardItem>? infoBoard;
@@ -185,7 +185,7 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
})(); })();
timer = Timer.periodic(Duration(seconds: 1), (timer) async { timer = Timer.periodic(Duration(seconds: 1), (timer) async {
if (swipeBack > 0) swipeBack -= 1; if (swipeBack != null) swipeBack = swipeBack! - 1;
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
now = timeNow(); now = timeNow();
@@ -262,13 +262,15 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
? lessons!.length + 1 ? lessons!.length + 1
: lessons!.indexOf(currentLesson) + 1; : lessons!.indexOf(currentLesson) + 1;
if (tmpIndex != activeLessonIndex) { if (activeLessonIndex == null || tmpIndex != activeLessonIndex) {
activeLessonIndex = tmpIndex; activeLessonIndex = tmpIndex;
swipeBack = 0; swipeBack = 0;
} }
centeredPageIndex ??= activeLessonIndex!;
if (controller.ready && swipeBack == 0) { if (controller.ready && swipeBack == 0) {
controller.animateToPage(activeLessonIndex); controller.animateToPage(activeLessonIndex!);
} }
int testsTomorrow = testItems int testsTomorrow = testItems
@@ -385,22 +387,20 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
], ],
carouselController: controller, carouselController: controller,
options: CarouselOptions( options: CarouselOptions(
initialPage: activeLessonIndex, initialPage: activeLessonIndex!,
height: 106, height: 106,
viewportFraction: 346 / 376, viewportFraction: 346 / 376,
enableInfiniteScroll: false, enableInfiniteScroll: false,
onPageChanged: (index, reason) { onPageChanged: (index, reason) {
centeredPageIndex = index; centeredPageIndex = index;
if (index == activeLessonIndex) { if (index == activeLessonIndex) {
swipeBack = -1; swipeBack = null;
} else if (reason == CarouselPageChangedReason.manual) { } else if (reason == CarouselPageChangedReason.manual) {
swipeBack = 5; swipeBack = 5;
} else { } else {
return; return;
} }
setState(() { setState(() {});
centeredPageIndex = index;
});
}, },
), ),
), ),