From 18f40b115f36832ab889900689832d5b95761b6f Mon Sep 17 00:00:00 2001 From: Jacques Date: Mon, 6 Nov 2023 13:42:54 +0100 Subject: [PATCH 1/3] feat: Added the border scroll feature. Next page is opened when scrolling to specific offset --- lib/src/timetable.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/src/timetable.dart b/lib/src/timetable.dart index 124e41a..2c43ee4 100644 --- a/lib/src/timetable.dart +++ b/lib/src/timetable.dart @@ -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 createState() => _TimetableState(); } @@ -90,6 +95,7 @@ class _TimetableState extends State { @override void initState() { super.initState(); + _scrollController = widget.scrollController ?? ScrollController(initialScrollOffset: 0); if (widget.timeBlocks.isNotEmpty) { @@ -97,6 +103,30 @@ class _TimetableState extends State { } 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 From e05105d452b5d277f0445a343aee0dda8d418e38 Mon Sep 17 00:00:00 2001 From: Jacques Date: Mon, 6 Nov 2023 13:49:47 +0100 Subject: [PATCH 2/3] fix: version and changelog --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/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: From dd88521c9dbfe7a79ebe3c8552fdc934d7934354 Mon Sep 17 00:00:00 2001 From: Jacques Date: Tue, 7 Nov 2023 09:46:17 +0100 Subject: [PATCH 3/3] fix: Removed the magic numbers --- lib/src/timetable.dart | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/src/timetable.dart b/lib/src/timetable.dart index 2c43ee4..1152a11 100644 --- a/lib/src/timetable.dart +++ b/lib/src/timetable.dart @@ -35,8 +35,13 @@ class Timetable extends StatefulWidget { this.combineBlocks = true, this.onOverScroll, this.onUnderScroll, - Key? key, - }) : super(key: key); + 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; @@ -82,6 +87,12 @@ 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; @@ -108,19 +119,21 @@ class _TimetableState extends State { _scrollController.addListener(() { if (_scrollController.offset - _scrollController.position.maxScrollExtent > - 120) { + widget.scrollTriggerOffset) { if (widget.onOverScroll != null) { - _scrollController - .jumpTo(_scrollController.position.minScrollExtent - 115); + _scrollController.jumpTo( + _scrollController.position.minScrollExtent - + widget.scrollJumpToOffset); widget.onOverScroll?.call(); } } else if (_scrollController.position.minScrollExtent - _scrollController.offset > - 120) { + widget.scrollTriggerOffset) { if (widget.onUnderScroll != null) { - _scrollController - .jumpTo(_scrollController.position.maxScrollExtent + 115); + _scrollController.jumpTo( + _scrollController.position.maxScrollExtent + + widget.scrollJumpToOffset); widget.onUnderScroll?.call(); }