mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
feat: ability to sort on starttime
This commit is contained in:
parent
32b9f9f2c5
commit
8b333e7bb7
2 changed files with 16 additions and 0 deletions
|
@ -34,3 +34,5 @@
|
|||
## [2.0.0] - 03 December 2023
|
||||
|
||||
* Create Melos variant of the component where there are multiple packages in the same repository.
|
||||
|
||||
* Added the option to sort on the starttime of an event.
|
||||
|
|
|
@ -36,6 +36,7 @@ class Timetable extends StatefulWidget {
|
|||
this.mergeBlocks = false,
|
||||
this.combineBlocks = true,
|
||||
this.sortByIdAscending = false,
|
||||
this.sortByStartTime = false,
|
||||
this.onOverScroll,
|
||||
this.onUnderScroll,
|
||||
this.scrollTriggerOffset = 120,
|
||||
|
@ -102,6 +103,9 @@ class Timetable extends StatefulWidget {
|
|||
/// Whether or not to sort blocks by their ID in ascending order.
|
||||
final bool sortByIdAscending;
|
||||
|
||||
/// Whether or not to sort blocks by their StartTime.
|
||||
final bool sortByStartTime;
|
||||
|
||||
/// The offset which trigger the jump to either the previous or next page. Can't be lower then [scrollJumpToOffset].
|
||||
final double scrollTriggerOffset;
|
||||
|
||||
|
@ -157,6 +161,12 @@ class _TimetableState extends State<Timetable> {
|
|||
}
|
||||
}
|
||||
|
||||
int compareTimeOfDay(TimeOfDay time1, TimeOfDay time2) {
|
||||
var totalMinutes1 = time1.hour * 60 + time1.minute;
|
||||
var totalMinutes2 = time2.hour * 60 + time2.minute;
|
||||
return totalMinutes1.compareTo(totalMinutes2);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.scrollController == null) {
|
||||
|
@ -181,6 +191,10 @@ class _TimetableState extends State<Timetable> {
|
|||
));
|
||||
}
|
||||
|
||||
if (widget.sortByStartTime) {
|
||||
blocks.sort((a, b) => compareTimeOfDay(a.start, b.start));
|
||||
}
|
||||
|
||||
var linePadding = _calculateTableTextSize().width;
|
||||
return SizedBox(
|
||||
width: widget.size?.width,
|
||||
|
|
Loading…
Reference in a new issue