forked from firka/firka
fix: display current lesson on homepage
This commit is contained in:
@@ -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;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user