2022-11-01 09:46:23 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-08-26 09:04:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:timetable/src/models/table_theme.dart';
|
2022-08-24 11:01:50 +02:00
|
|
|
|
|
|
|
class Table extends StatelessWidget {
|
2022-08-26 09:04:08 +02:00
|
|
|
/// The [Table] to draw an overview of timerange with corresponding hour lines
|
2022-08-24 11:01:50 +02:00
|
|
|
const Table({
|
|
|
|
required this.startHour,
|
|
|
|
required this.endHour,
|
2022-08-26 09:04:08 +02:00
|
|
|
this.hourHeight = 80,
|
|
|
|
this.tableOffset = 40,
|
2022-08-24 13:32:35 +02:00
|
|
|
this.theme = const TableTheme(),
|
2022-08-24 11:01:50 +02:00
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-08-26 09:04:08 +02:00
|
|
|
/// The hour the table starts at.
|
2022-08-24 11:01:50 +02:00
|
|
|
final int startHour;
|
2022-08-26 09:04:08 +02:00
|
|
|
|
|
|
|
/// The hour the table ends at.
|
2022-08-24 11:01:50 +02:00
|
|
|
final int endHour;
|
2022-08-26 09:04:08 +02:00
|
|
|
|
|
|
|
/// The height of a single hour in the table.
|
|
|
|
final double hourHeight;
|
|
|
|
|
|
|
|
/// The offset of the table;
|
|
|
|
final double tableOffset;
|
|
|
|
|
|
|
|
/// The theme used by the table.
|
2022-08-24 13:32:35 +02:00
|
|
|
final TableTheme theme;
|
2022-08-24 11:01:50 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
for (int i = startHour; i <= endHour; i++) ...[
|
|
|
|
SizedBox(
|
2022-08-26 09:04:08 +02:00
|
|
|
height: i == endHour ? hourHeight / 2 : hourHeight,
|
2022-08-24 11:01:50 +02:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-08-24 12:03:32 +02:00
|
|
|
'${i.toString().padLeft(2, '0')}:00',
|
2022-09-01 12:05:37 +02:00
|
|
|
style: theme.timeStyle ??
|
|
|
|
Theme.of(context).textTheme.bodyText1,
|
2022-08-24 11:01:50 +02:00
|
|
|
),
|
2022-08-26 09:04:08 +02:00
|
|
|
SizedBox(
|
|
|
|
width: theme.tableTextOffset,
|
2022-08-24 11:01:50 +02:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
2022-08-24 13:32:35 +02:00
|
|
|
height: theme.lineHeight,
|
|
|
|
color: theme.lineColor,
|
2022-08-24 11:01:50 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (i != endHour) ...[
|
|
|
|
const Spacer(),
|
|
|
|
Container(
|
2022-08-26 09:04:08 +02:00
|
|
|
margin: EdgeInsets.only(
|
|
|
|
left: tableOffset,
|
2022-08-24 11:01:50 +02:00
|
|
|
),
|
2022-08-24 13:32:35 +02:00
|
|
|
height: theme.lineHeight,
|
2022-08-24 11:01:50 +02:00
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-08-26 09:04:08 +02:00
|
|
|
for (int i = 0; i < theme.lineDashFrequency; i++) ...[
|
2022-08-24 11:01:50 +02:00
|
|
|
Container(
|
2022-08-26 09:04:08 +02:00
|
|
|
width: (MediaQuery.of(context).size.width -
|
|
|
|
tableOffset) /
|
|
|
|
theme.lineDashFrequency,
|
2022-08-24 13:32:35 +02:00
|
|
|
height: theme.lineHeight,
|
|
|
|
color:
|
|
|
|
i.isEven ? theme.lineColor : Colors.transparent,
|
2022-08-24 11:01:50 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|