Skip to content

Commit 01a7cff

Browse files
authored
Merge pull request #12 from Iconica-Development/1.3.0
feat: add ability to offset hours so table can span across midnight
2 parents f79ae93 + dc338d4 commit 01a7cff

8 files changed

Lines changed: 25 additions & 233 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
## [1.2.1] - 7 November 2023
2323

2424
* Fixed the assert on the [scrollTriggerOffset] and [scrollJumpToOffset].
25+
26+
## [1.3.0] - 8 November 2023
27+
28+
* 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.

example/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ migrate_working_dir/
1919
# The .vscode folder contains launch configuration and tasks you configure in
2020
# VS Code which you may wish to be included in version control, so this line
2121
# is commented out by default.
22-
#.vscode/
22+
.vscode/
2323

2424
# Flutter/Dart/Pub related
2525
**/doc/api/
@@ -45,3 +45,6 @@ app.*.map.json
4545
/android/app/debug
4646
/android/app/profile
4747
/android/app/release
48+
49+
pubspec.lock
50+
.metadata

example/.metadata

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ class _TimetableDemoState extends State<TimetableDemo> {
149149
child: Timetable(
150150
onOverScroll: () {},
151151
onUnderScroll: () {},
152+
hoursOffset: 6,
152153
size: Size(size.width, size.height * 0.64),
153154
tableDirection: _horizontal ? Axis.horizontal : Axis.vertical,
154-
startHour: 3,
155+
startHour: 0,
155156
endHour: 24,
156157
timeBlocks: blocks,
157158
scrollController: _scrollController,

example/pubspec.lock

Lines changed: 0 additions & 196 deletions
This file was deleted.

lib/src/timetable.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Timetable extends StatefulWidget {
2525
this.initialScrollTime,
2626
this.scrollController,
2727
this.scrollPhysics,
28+
this.hoursOffset = 0,
2829
this.startHour = 0,
2930
this.endHour = 24,
3031
this.blockDimension = 50,
@@ -55,6 +56,10 @@ class Timetable extends StatefulWidget {
5556
/// Hour at which the timetable ends.
5657
final int endHour;
5758

59+
/// The time offset to increase all hour labels with
60+
/// this is used to make the timetable start at a different time and go past midnight.
61+
final int hoursOffset;
62+
5863
/// The time blocks that will be displayed in the timetable.
5964
final List<TimeBlock> timeBlocks;
6065

@@ -170,6 +175,7 @@ class _TimetableState extends State<Timetable> {
170175
alignment: Alignment.topLeft,
171176
children: [
172177
table.Table(
178+
hoursOffset: widget.hoursOffset,
173179
tableDirection: widget.tableDirection,
174180
startHour: widget.startHour,
175181
endHour: widget.endHour,

lib/src/widgets/table.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ class Table extends StatelessWidget {
1010
const Table({
1111
required this.startHour,
1212
required this.endHour,
13+
this.hoursOffset = 0,
1314
this.size,
1415
this.tableDirection = Axis.vertical,
1516
this.hourDimension = 80,
1617
this.tableOffset = 20,
1718
this.theme = const TableTheme(),
18-
Key? key,
19-
}) : super(key: key);
19+
super.key,
20+
});
2021

2122
/// The [Axis] in which the table is layed out.
2223
final Axis tableDirection;
@@ -30,6 +31,9 @@ class Table extends StatelessWidget {
3031
/// The hour the table ends at.
3132
final int endHour;
3233

34+
/// The time offset to increase all hour labels with
35+
final int hoursOffset;
36+
3337
/// The length in pixel of a single hour in the table.
3438
final double hourDimension;
3539

@@ -55,7 +59,7 @@ class Table extends StatelessWidget {
5559
Column(
5660
children: [
5761
Text(
58-
'${((i == 24) ? '00' : i.toString()).padLeft(2, '0')}'
62+
'${(((i + hoursOffset) == 24) ? '00' : ((i + hoursOffset) % 24).toString()).padLeft(2, '0')}'
5963
':00',
6064
style: theme.timeStyle ??
6165
Theme.of(context).textTheme.bodyLarge,
@@ -124,7 +128,7 @@ class Table extends StatelessWidget {
124128
Row(
125129
children: [
126130
Text(
127-
'${i.toString().padLeft(2, '0')}:00',
131+
'${((i + hoursOffset) % 24).toString().padLeft(2, '0')}:00',
128132
style: theme.timeStyle ??
129133
Theme.of(context).textTheme.bodyLarge,
130134
),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_timetable
22
description: Flutter package to create a Timetable Widget that display blocks of widgets inside a timetable.
3-
version: 1.2.1
3+
version: 1.3.0
44
repository: https://github.com/Iconica-Development/timetable
55

66
environment:

0 commit comments

Comments
 (0)