feat: ability to sort on starttime

This commit is contained in:
mike doornenbal 2023-12-11 10:06:40 +01:00
parent 32b9f9f2c5
commit 8b333e7bb7
2 changed files with 16 additions and 0 deletions

View file

@ -34,3 +34,5 @@
## [2.0.0] - 03 December 2023 ## [2.0.0] - 03 December 2023
* Create Melos variant of the component where there are multiple packages in the same repository. * 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.

View file

@ -36,6 +36,7 @@ class Timetable extends StatefulWidget {
this.mergeBlocks = false, this.mergeBlocks = false,
this.combineBlocks = true, this.combineBlocks = true,
this.sortByIdAscending = false, this.sortByIdAscending = false,
this.sortByStartTime = false,
this.onOverScroll, this.onOverScroll,
this.onUnderScroll, this.onUnderScroll,
this.scrollTriggerOffset = 120, this.scrollTriggerOffset = 120,
@ -102,6 +103,9 @@ class Timetable extends StatefulWidget {
/// Whether or not to sort blocks by their ID in ascending order. /// Whether or not to sort blocks by their ID in ascending order.
final bool sortByIdAscending; 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]. /// The offset which trigger the jump to either the previous or next page. Can't be lower then [scrollJumpToOffset].
final double scrollTriggerOffset; 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 @override
void dispose() { void dispose() {
if (widget.scrollController == null) { 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; var linePadding = _calculateTableTextSize().width;
return SizedBox( return SizedBox(
width: widget.size?.width, width: widget.size?.width,