Merge pull request #9 from Iconica-Development/feature/border_scroll

feat: Added the border scroll feature. Next page is opened when scrol…
This commit is contained in:
Gorter-dev 2023-11-07 10:06:50 +01:00 committed by GitHub
commit 77d5e2fb36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 3 deletions

View file

@ -14,3 +14,7 @@
## [1.1.0] - 17 August 2023 ## [1.1.0] - 17 August 2023
* Set scrolling to the current time by default if there are no blocks * 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.

View file

@ -33,8 +33,15 @@ class Timetable extends StatefulWidget {
this.theme = const TableTheme(), this.theme = const TableTheme(),
this.mergeBlocks = false, this.mergeBlocks = false,
this.combineBlocks = true, this.combineBlocks = true,
Key? key, this.onOverScroll,
}) : super(key: key); 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. /// The Axis in which the table is layed out.
final Axis tableDirection; 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. /// 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()? onOverScroll;
@override @override
State<Timetable> createState() => _TimetableState(); State<Timetable> createState() => _TimetableState();
} }
@ -90,6 +106,7 @@ class _TimetableState extends State<Timetable> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_scrollController = _scrollController =
widget.scrollController ?? ScrollController(initialScrollOffset: 0); widget.scrollController ?? ScrollController(initialScrollOffset: 0);
if (widget.timeBlocks.isNotEmpty) { if (widget.timeBlocks.isNotEmpty) {
@ -97,6 +114,32 @@ class _TimetableState extends State<Timetable> {
} else { } else {
_scrollToInitialTime(); _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 @override

View file

@ -1,6 +1,6 @@
name: flutter_timetable name: flutter_timetable
description: Flutter package to create a Timetable Widget that display blocks of widgets inside a 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 repository: https://github.com/Iconica-Development/timetable
environment: environment: