fix: Removed the magic numbers

This commit is contained in:
Jacques 2023-11-07 09:46:17 +01:00
parent e05105d452
commit dd88521c9d

View file

@ -35,8 +35,13 @@ class Timetable extends StatefulWidget {
this.combineBlocks = true, this.combineBlocks = true,
this.onOverScroll, this.onOverScroll,
this.onUnderScroll, this.onUnderScroll,
Key? key, this.scrollTriggerOffset = 120,
}) : super(key: key); this.scrollJumpToOffset = 115,
super.key,
}) : assert(
scrollTriggerOffset < scrollJumpToOffset,
'ScrollTriggerOffset cannot be smaller'
' then the scrollJumpToOffset.');
/// The Axis in which the table is layed out. /// The Axis in which the table is layed out.
final Axis tableDirection; final Axis tableDirection;
@ -82,6 +87,12 @@ class Timetable extends StatefulWidget {
/// If blocks have the same id and time they will be combined into one block. /// If blocks have the same id and time they will be combined into one block.
final bool combineBlocks; final bool combineBlocks;
/// The offset which trigger the jump to either the previous or next page. Can't be lower then [scrollJumpToOffset].
final double scrollTriggerOffset;
/// When the jump is triggered this offset will be jumped outside of the min or max offset. Can't be higher then [scrollTriggerOffset].
final double scrollJumpToOffset;
final void Function()? onUnderScroll; final void Function()? onUnderScroll;
final void Function()? onOverScroll; final void Function()? onOverScroll;
@ -108,19 +119,21 @@ class _TimetableState extends State<Timetable> {
_scrollController.addListener(() { _scrollController.addListener(() {
if (_scrollController.offset - if (_scrollController.offset -
_scrollController.position.maxScrollExtent > _scrollController.position.maxScrollExtent >
120) { widget.scrollTriggerOffset) {
if (widget.onOverScroll != null) { if (widget.onOverScroll != null) {
_scrollController _scrollController.jumpTo(
.jumpTo(_scrollController.position.minScrollExtent - 115); _scrollController.position.minScrollExtent -
widget.scrollJumpToOffset);
widget.onOverScroll?.call(); widget.onOverScroll?.call();
} }
} else if (_scrollController.position.minScrollExtent - } else if (_scrollController.position.minScrollExtent -
_scrollController.offset > _scrollController.offset >
120) { widget.scrollTriggerOffset) {
if (widget.onUnderScroll != null) { if (widget.onUnderScroll != null) {
_scrollController _scrollController.jumpTo(
.jumpTo(_scrollController.position.maxScrollExtent + 115); _scrollController.position.maxScrollExtent +
widget.scrollJumpToOffset);
widget.onUnderScroll?.call(); widget.onUnderScroll?.call();
} }