mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
feat: add option to sort the blocks by their id
This commit is contained in:
parent
01a7cfffb1
commit
93b25c7db6
4 changed files with 29 additions and 7 deletions
|
@ -26,3 +26,7 @@
|
|||
## [1.3.0] - 8 November 2023
|
||||
|
||||
* Add the option for setting an offset for the hours so that the first hour is not 00:00 but 08:00 for example and the last hour can be after 24:00.
|
||||
|
||||
## [1.4.0] - 13 November 2023
|
||||
|
||||
* Add the option for sorting the blocks by their id.
|
|
@ -34,7 +34,7 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
|||
),
|
||||
),
|
||||
),
|
||||
id: 1,
|
||||
id: 3,
|
||||
),
|
||||
TimeBlock(
|
||||
start: const TimeOfDay(hour: 10, minute: 0),
|
||||
|
@ -50,7 +50,7 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
|||
),
|
||||
),
|
||||
childDimension: 300,
|
||||
id: 3,
|
||||
id: 1,
|
||||
),
|
||||
TimeBlock(
|
||||
start: const TimeOfDay(hour: 14, minute: 0),
|
||||
|
@ -150,6 +150,7 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
|||
onOverScroll: () {},
|
||||
onUnderScroll: () {},
|
||||
hoursOffset: 6,
|
||||
sortByIdAscending: true,
|
||||
size: Size(size.width, size.height * 0.64),
|
||||
tableDirection: _horizontal ? Axis.horizontal : Axis.vertical,
|
||||
startHour: 0,
|
||||
|
|
|
@ -34,15 +34,21 @@ class Timetable extends StatefulWidget {
|
|||
this.theme = const TableTheme(),
|
||||
this.mergeBlocks = false,
|
||||
this.combineBlocks = true,
|
||||
this.sortByIdAscending = false,
|
||||
this.onOverScroll,
|
||||
this.onUnderScroll,
|
||||
this.scrollTriggerOffset = 120,
|
||||
this.scrollJumpToOffset = 115,
|
||||
super.key,
|
||||
}) : assert(
|
||||
scrollTriggerOffset > scrollJumpToOffset,
|
||||
'ScrollTriggerOffset cannot be smaller'
|
||||
' then the scrollJumpToOffset.');
|
||||
}) : assert(
|
||||
scrollTriggerOffset > scrollJumpToOffset,
|
||||
'ScrollTriggerOffset cannot be smaller'
|
||||
' then the scrollJumpToOffset.',
|
||||
),
|
||||
assert(
|
||||
!(mergeBlocks && sortByIdAscending),
|
||||
'mergeBlocks and sortByIdAscending'
|
||||
' cannot be enabled at the same time.');
|
||||
|
||||
/// The Axis in which the table is layed out.
|
||||
final Axis tableDirection;
|
||||
|
@ -92,6 +98,9 @@ class Timetable extends StatefulWidget {
|
|||
/// If blocks have the same id and time they will be combined into one block.
|
||||
final bool combineBlocks;
|
||||
|
||||
/// Whether or not to sort blocks by their ID in ascending order.
|
||||
final bool sortByIdAscending;
|
||||
|
||||
/// The offset which trigger the jump to either the previous or next page. Can't be lower then [scrollJumpToOffset].
|
||||
final double scrollTriggerOffset;
|
||||
|
||||
|
@ -163,6 +172,14 @@ class _TimetableState extends State<Timetable> {
|
|||
} else {
|
||||
blocks = widget.timeBlocks;
|
||||
}
|
||||
|
||||
if (widget.sortByIdAscending) {
|
||||
// if the id is zero then put it at the end
|
||||
blocks.sort((a, b) => (a.id != 0 ? a.id : double.infinity).compareTo(
|
||||
(b.id != 0 ? b.id : double.infinity),
|
||||
));
|
||||
}
|
||||
|
||||
var linePadding = _calculateTableTextSize().width;
|
||||
return SizedBox(
|
||||
width: widget.size?.width,
|
||||
|
|
|
@ -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.3.0
|
||||
version: 1.4.0
|
||||
repository: https://github.com/Iconica-Development/timetable
|
||||
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue