diff --git a/CHANGELOG.md b/CHANGELOG.md index 32b6cc1..1118688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,3 +14,7 @@ ## [1.1.0] - 17 August 2023 * Set scrolling to the current time by default if there are no blocks + +## [1.2.0] - 6 November 2023 + +* Add the ability to use BorderScroll. If enabled the next page is shown when scrolling to an specific offset. diff --git a/lib/src/timetable.dart b/lib/src/timetable.dart index 124e41a..1152a11 100644 --- a/lib/src/timetable.dart +++ b/lib/src/timetable.dart @@ -33,8 +33,15 @@ class Timetable extends StatefulWidget { this.theme = const TableTheme(), this.mergeBlocks = false, this.combineBlocks = true, - Key? key, - }) : super(key: key); + this.onOverScroll, + this.onUnderScroll, + this.scrollTriggerOffset = 120, + this.scrollJumpToOffset = 115, + super.key, + }) : assert( + scrollTriggerOffset < scrollJumpToOffset, + 'ScrollTriggerOffset cannot be smaller' + ' then the scrollJumpToOffset.'); /// The Axis in which the table is layed out. final Axis tableDirection; @@ -80,6 +87,15 @@ class Timetable extends StatefulWidget { /// If blocks have the same id and time they will be combined into one block. 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()? onOverScroll; + @override State createState() => _TimetableState(); } @@ -90,6 +106,7 @@ class _TimetableState extends State { @override void initState() { super.initState(); + _scrollController = widget.scrollController ?? ScrollController(initialScrollOffset: 0); if (widget.timeBlocks.isNotEmpty) { @@ -97,6 +114,32 @@ class _TimetableState extends State { } else { _scrollToInitialTime(); } + + if (widget.onUnderScroll != null && widget.onOverScroll != null) { + _scrollController.addListener(() { + if (_scrollController.offset - + _scrollController.position.maxScrollExtent > + widget.scrollTriggerOffset) { + if (widget.onOverScroll != null) { + _scrollController.jumpTo( + _scrollController.position.minScrollExtent - + widget.scrollJumpToOffset); + + widget.onOverScroll?.call(); + } + } else if (_scrollController.position.minScrollExtent - + _scrollController.offset > + widget.scrollTriggerOffset) { + if (widget.onUnderScroll != null) { + _scrollController.jumpTo( + _scrollController.position.maxScrollExtent + + widget.scrollJumpToOffset); + + widget.onUnderScroll?.call(); + } + } + }); + } } @override diff --git a/pubspec.yaml b/pubspec.yaml index ac95d29..fe2a1a1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_timetable description: Flutter package to create a Timetable Widget that display blocks of widgets inside a timetable. -version: 1.1.0 +version: 1.2.0 repository: https://github.com/Iconica-Development/timetable environment: