feat: Added the border scroll feature. Next page is opened when scrolling to specific offset

This commit is contained in:
Jacques 2023-11-06 13:42:54 +01:00
parent 2d081f8efa
commit 18f40b115f

View file

@ -33,6 +33,8 @@ class Timetable extends StatefulWidget {
this.theme = const TableTheme(),
this.mergeBlocks = false,
this.combineBlocks = true,
this.onOverScroll,
this.onUnderScroll,
Key? key,
}) : super(key: key);
@ -80,6 +82,9 @@ class Timetable extends StatefulWidget {
/// If blocks have the same id and time they will be combined into one block.
final bool combineBlocks;
final void Function()? onUnderScroll;
final void Function()? onOverScroll;
@override
State<Timetable> createState() => _TimetableState();
}
@ -90,6 +95,7 @@ class _TimetableState extends State<Timetable> {
@override
void initState() {
super.initState();
_scrollController =
widget.scrollController ?? ScrollController(initialScrollOffset: 0);
if (widget.timeBlocks.isNotEmpty) {
@ -97,6 +103,30 @@ class _TimetableState extends State<Timetable> {
} else {
_scrollToInitialTime();
}
if (widget.onUnderScroll != null && widget.onOverScroll != null) {
_scrollController.addListener(() {
if (_scrollController.offset -
_scrollController.position.maxScrollExtent >
120) {
if (widget.onOverScroll != null) {
_scrollController
.jumpTo(_scrollController.position.minScrollExtent - 115);
widget.onOverScroll?.call();
}
} else if (_scrollController.position.minScrollExtent -
_scrollController.offset >
120) {
if (widget.onUnderScroll != null) {
_scrollController
.jumpTo(_scrollController.position.maxScrollExtent + 115);
widget.onUnderScroll?.call();
}
}
});
}
}
@override