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';
|
2022-08-24 12:03:32 +02:00
|
|
|
|
|
|
|
class Block extends StatelessWidget {
|
2022-08-26 09:04:08 +02:00
|
|
|
/// The [Block] to create a Widget or container in a [TimeTable].
|
2022-08-24 12:03:32 +02:00
|
|
|
const Block({
|
|
|
|
required this.start,
|
|
|
|
required this.end,
|
|
|
|
required this.startHour,
|
2022-11-08 10:33:48 +01:00
|
|
|
required this.blockDimension,
|
|
|
|
required this.hourDimension,
|
|
|
|
required this.blockDirection,
|
2022-11-22 16:06:34 +01:00
|
|
|
this.blockColor = Colors.blue,
|
2022-08-24 12:03:32 +02:00
|
|
|
this.linePadding = 8,
|
|
|
|
this.child,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-11-08 10:33:48 +01:00
|
|
|
/// The [Axis] along which the [Block] will be displayed.
|
|
|
|
final Axis blockDirection;
|
|
|
|
|
2022-08-24 12:03:32 +02:00
|
|
|
/// The start time of the block in 24 hour format
|
|
|
|
final TimeOfDay start;
|
|
|
|
|
|
|
|
/// The end time of the block in 24 hour format
|
|
|
|
final TimeOfDay end;
|
|
|
|
|
2022-11-08 10:33:48 +01:00
|
|
|
/// Widget that will be displayed within the block
|
2022-08-24 12:03:32 +02:00
|
|
|
final Widget? child;
|
|
|
|
|
|
|
|
/// The start hour of the timetable.
|
|
|
|
final int startHour;
|
|
|
|
|
2022-11-08 10:33:48 +01:00
|
|
|
/// The dimension in pixels of one hour in the timetable
|
|
|
|
final double hourDimension;
|
2022-08-24 13:32:35 +02:00
|
|
|
|
2022-11-08 10:33:48 +01:00
|
|
|
/// The dimension in pixels of the block if there is no child
|
|
|
|
final double blockDimension;
|
2022-08-24 12:03:32 +02:00
|
|
|
|
2022-08-24 13:32:35 +02:00
|
|
|
/// The color of the block if there is no child
|
|
|
|
final Color blockColor;
|
|
|
|
|
2022-08-24 12:03:32 +02:00
|
|
|
/// The padding between the lines and the numbers
|
|
|
|
final double linePadding;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2022-11-22 16:06:34 +01:00
|
|
|
color: blockColor,
|
2022-08-24 12:03:32 +02:00
|
|
|
margin: EdgeInsets.only(
|
2022-11-08 10:33:48 +01:00
|
|
|
top: (blockDirection == Axis.vertical)
|
|
|
|
? (((start.hour - startHour) * Duration.minutesPerHour) +
|
|
|
|
start.minute) *
|
|
|
|
_sizePerMinute() +
|
|
|
|
linePadding
|
|
|
|
: 0,
|
|
|
|
left: (blockDirection == Axis.horizontal)
|
|
|
|
? ((((start.hour - startHour) * Duration.minutesPerHour) +
|
|
|
|
start.minute) *
|
|
|
|
_sizePerMinute() +
|
|
|
|
linePadding)
|
|
|
|
: 0,
|
2022-08-24 12:03:32 +02:00
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
height: (blockDirection == Axis.vertical)
|
|
|
|
? (((end.hour - start.hour) * Duration.minutesPerHour) +
|
|
|
|
end.minute -
|
|
|
|
start.minute) *
|
|
|
|
_sizePerMinute()
|
|
|
|
: null,
|
|
|
|
width: (blockDirection == Axis.horizontal)
|
|
|
|
? (((end.hour - start.hour) * Duration.minutesPerHour) +
|
|
|
|
end.minute -
|
|
|
|
start.minute) *
|
|
|
|
_sizePerMinute()
|
|
|
|
: null,
|
2022-08-24 12:03:32 +02:00
|
|
|
child: child ??
|
2022-11-22 16:06:34 +01:00
|
|
|
SizedBox(
|
2022-11-08 10:33:48 +01:00
|
|
|
height: (blockDirection == Axis.horizontal) ? blockDimension : 0,
|
|
|
|
width: (blockDirection == Axis.vertical) ? blockDimension : 0,
|
2022-08-24 12:03:32 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-26 09:04:08 +02:00
|
|
|
double _sizePerMinute() {
|
2022-11-08 10:33:48 +01:00
|
|
|
return hourDimension / Duration.minutesPerHour;
|
2022-08-24 12:03:32 +02:00
|
|
|
}
|
|
|
|
}
|