flutter_timetable/lib/src/widgets/table.dart

93 lines
2.7 KiB
Dart
Raw Normal View History

2022-11-01 09:46:23 +01:00
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
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 {
/// 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,
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);
/// The hour the table starts at.
2022-08-24 11:01:50 +02:00
final int startHour;
/// The hour the table ends at.
2022-08-24 11:01:50 +02:00
final int endHour;
/// 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(
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
),
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(
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: [
for (int i = 0; i < theme.lineDashFrequency; i++) ...[
2022-08-24 11:01:50 +02:00
Container(
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(),
],
],
),
),
],
],
);
}
}