mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-19 03:43:43 +02:00
feat: add table size option
This commit is contained in:
parent
8a62eff0b8
commit
6aaf5dc171
3 changed files with 144 additions and 123 deletions
|
@ -121,10 +121,11 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var size = MediaQuery.of(context).size;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
// backgroundColor: Colors.green,
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// toggle between horizontal and vertical
|
// toggle between horizontal and vertical
|
||||||
|
@ -156,10 +157,13 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Timetable(
|
Container(
|
||||||
|
color: Colors.white,
|
||||||
|
child: Timetable(
|
||||||
|
size: Size(size.width, size.height * 0.64),
|
||||||
tableDirection: _horizontal ? Axis.horizontal : Axis.vertical,
|
tableDirection: _horizontal ? Axis.horizontal : Axis.vertical,
|
||||||
startHour: 3,
|
startHour: 3,
|
||||||
endHour: 22,
|
endHour: 24,
|
||||||
timeBlocks: blocks,
|
timeBlocks: blocks,
|
||||||
scrollController: _scrollController,
|
scrollController: _scrollController,
|
||||||
combineBlocks: true,
|
combineBlocks: true,
|
||||||
|
@ -169,8 +173,8 @@ class _TimetableDemoState extends State<TimetableDemo> {
|
||||||
blockPaddingBetween: 10,
|
blockPaddingBetween: 10,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,6 +21,7 @@ class Timetable extends StatefulWidget {
|
||||||
const Timetable({
|
const Timetable({
|
||||||
this.tableDirection = Axis.vertical,
|
this.tableDirection = Axis.vertical,
|
||||||
this.timeBlocks = const [],
|
this.timeBlocks = const [],
|
||||||
|
this.size,
|
||||||
this.scrollController,
|
this.scrollController,
|
||||||
this.scrollPhysics,
|
this.scrollPhysics,
|
||||||
this.startHour = 0,
|
this.startHour = 0,
|
||||||
|
@ -37,6 +38,9 @@ class Timetable extends StatefulWidget {
|
||||||
/// The Axis in which the table is layed out.
|
/// The Axis in which the table is layed out.
|
||||||
final Axis tableDirection;
|
final Axis tableDirection;
|
||||||
|
|
||||||
|
/// The [Size] of the timetable.
|
||||||
|
final Size? size;
|
||||||
|
|
||||||
/// Hour at which the timetable starts.
|
/// Hour at which the timetable starts.
|
||||||
final int startHour;
|
final int startHour;
|
||||||
|
|
||||||
|
@ -106,9 +110,10 @@ class _TimetableState extends State<Timetable> {
|
||||||
blocks = widget.timeBlocks;
|
blocks = widget.timeBlocks;
|
||||||
}
|
}
|
||||||
var linePadding = _calculateTableTextSize().width;
|
var linePadding = _calculateTableTextSize().width;
|
||||||
return SingleChildScrollView(
|
return SizedBox(
|
||||||
key: // TODO(freek): test if this is necessary
|
width: widget.size?.width,
|
||||||
ValueKey<int>(widget.timeBlocks.length),
|
height: widget.size?.height,
|
||||||
|
child: SingleChildScrollView(
|
||||||
physics: widget.scrollPhysics ?? const BouncingScrollPhysics(),
|
physics: widget.scrollPhysics ?? const BouncingScrollPhysics(),
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
scrollDirection: widget.tableDirection,
|
scrollDirection: widget.tableDirection,
|
||||||
|
@ -125,6 +130,7 @@ class _TimetableState extends State<Timetable> {
|
||||||
hourDimension: widget.hourDimension,
|
hourDimension: widget.hourDimension,
|
||||||
tableOffset: _calculateTableStart(widget.tableDirection).width,
|
tableOffset: _calculateTableStart(widget.tableDirection).width,
|
||||||
theme: widget.theme,
|
theme: widget.theme,
|
||||||
|
size: widget.size,
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(
|
||||||
|
@ -132,8 +138,6 @@ class _TimetableState extends State<Timetable> {
|
||||||
left: _calculateTableStart(widget.tableDirection).width,
|
left: _calculateTableStart(widget.tableDirection).width,
|
||||||
),
|
),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
key: // TODO(freek): test if this is necessary
|
|
||||||
ValueKey<int>(widget.timeBlocks.length),
|
|
||||||
physics: widget.scrollPhysics ?? const BouncingScrollPhysics(),
|
physics: widget.scrollPhysics ?? const BouncingScrollPhysics(),
|
||||||
scrollDirection: widget.tableDirection == Axis.horizontal
|
scrollDirection: widget.tableDirection == Axis.horizontal
|
||||||
? Axis.vertical
|
? Axis.vertical
|
||||||
|
@ -219,17 +223,20 @@ class _TimetableState extends State<Timetable> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size _calculateTableStart(Axis axis) {
|
Size _calculateTableStart(Axis axis) {
|
||||||
return Size(
|
return Size(
|
||||||
(axis == Axis.horizontal)
|
(axis == Axis.horizontal)
|
||||||
? 0
|
? _calculateTableTextSize().width / 2
|
||||||
: _calculateTableTextSize().width +
|
: _calculateTableTextSize().width +
|
||||||
widget.theme.tablePaddingStart +
|
widget.theme.tablePaddingStart +
|
||||||
widget.theme.tableTextOffset,
|
widget.theme.tableTextOffset,
|
||||||
(axis == Axis.vertical) ? 0 : _calculateTableTextSize().height,
|
(axis == Axis.vertical)
|
||||||
|
? _calculateTableTextSize().height / 2
|
||||||
|
: _calculateTableTextSize().height,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Table extends StatelessWidget {
|
||||||
const Table({
|
const Table({
|
||||||
required this.startHour,
|
required this.startHour,
|
||||||
required this.endHour,
|
required this.endHour,
|
||||||
|
this.size,
|
||||||
this.tableDirection = Axis.vertical,
|
this.tableDirection = Axis.vertical,
|
||||||
this.hourDimension = 80,
|
this.hourDimension = 80,
|
||||||
this.tableOffset = 20,
|
this.tableOffset = 20,
|
||||||
|
@ -24,6 +25,9 @@ class Table extends StatelessWidget {
|
||||||
/// The [Axis] in which the table is layed out.
|
/// The [Axis] in which the table is layed out.
|
||||||
final Axis tableDirection;
|
final Axis tableDirection;
|
||||||
|
|
||||||
|
/// The [Size] used for the table rendering.
|
||||||
|
final Size? size;
|
||||||
|
|
||||||
/// The hour the table starts at.
|
/// The hour the table starts at.
|
||||||
final int startHour;
|
final int startHour;
|
||||||
|
|
||||||
|
@ -64,7 +68,9 @@ class Table extends StatelessWidget {
|
||||||
Container(
|
Container(
|
||||||
color: theme.lineColor,
|
color: theme.lineColor,
|
||||||
width: theme.lineHeight,
|
width: theme.lineHeight,
|
||||||
height: tableHeight,
|
height: (size ?? MediaQuery.of(context).size).height -
|
||||||
|
textSize.dy -
|
||||||
|
theme.tableTextOffset,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -84,7 +90,11 @@ class Table extends StatelessWidget {
|
||||||
// draw dotted line
|
// draw dotted line
|
||||||
for (int i = 0;
|
for (int i = 0;
|
||||||
i <
|
i <
|
||||||
tableHeight /
|
(((size ?? MediaQuery.of(context).size)
|
||||||
|
.height) -
|
||||||
|
textSize.dy -
|
||||||
|
theme.tableTextOffset -
|
||||||
|
theme.lineDashDistance) /
|
||||||
((theme.lineDashLength +
|
((theme.lineDashLength +
|
||||||
theme.lineDashDistance) /
|
theme.lineDashDistance) /
|
||||||
2);
|
2);
|
||||||
|
@ -144,7 +154,7 @@ class Table extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
for (int i = 0;
|
for (int i = 0;
|
||||||
i <
|
i <
|
||||||
(MediaQuery.of(context).size.width -
|
((size ?? MediaQuery.of(context).size).width -
|
||||||
tableOffset -
|
tableOffset -
|
||||||
textSize.dx / 2) /
|
textSize.dx / 2) /
|
||||||
((theme.lineDashLength +
|
((theme.lineDashLength +
|
||||||
|
|
Loading…
Reference in a new issue