mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
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:
commit
77d5e2fb36
3 changed files with 50 additions and 3 deletions
|
@ -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.
|
||||
|
|
|
@ -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<Timetable> createState() => _TimetableState();
|
||||
}
|
||||
|
@ -90,6 +106,7 @@ class _TimetableState extends State<Timetable> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_scrollController =
|
||||
widget.scrollController ?? ScrollController(initialScrollOffset: 0);
|
||||
if (widget.timeBlocks.isNotEmpty) {
|
||||
|
@ -97,6 +114,32 @@ class _TimetableState extends State<Timetable> {
|
|||
} 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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue