mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
feat: add ability to sort on starttime
This commit is contained in:
parent
e2bd94639f
commit
52d0b8f5da
2 changed files with 19 additions and 1 deletions
|
@ -29,4 +29,8 @@
|
|||
|
||||
## [1.4.0] - 13 November 2023
|
||||
|
||||
* Add the option for sorting the blocks by their id.
|
||||
* Add the option for sorting the blocks by their id.
|
||||
|
||||
## [1.5.0] - 10 May 2024
|
||||
|
||||
* Added the option to sort on the starttime of an event.
|
||||
|
|
|
@ -35,6 +35,7 @@ class Timetable extends StatefulWidget {
|
|||
this.mergeBlocks = false,
|
||||
this.combineBlocks = true,
|
||||
this.sortByIdAscending = false,
|
||||
this.sortByStartTime = false,
|
||||
this.onOverScroll,
|
||||
this.onUnderScroll,
|
||||
this.scrollTriggerOffset = 120,
|
||||
|
@ -101,6 +102,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;
|
||||
|
||||
|
@ -156,6 +160,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) {
|
||||
|
@ -180,6 +190,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