2022-08-24 12:03:32 +02:00
|
|
|
part of timetable;
|
|
|
|
|
|
|
|
class Block extends StatelessWidget {
|
|
|
|
const Block({
|
|
|
|
required this.start,
|
|
|
|
required this.end,
|
|
|
|
required this.startHour,
|
|
|
|
required this.blockWidth,
|
2022-08-24 13:32:35 +02:00
|
|
|
required this.hourHeight,
|
|
|
|
this.blockColor = const Color(0x80FF0000),
|
2022-08-24 12:03:32 +02:00
|
|
|
this.linePadding = 8,
|
|
|
|
this.child,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
|
|
|
|
/// Widget that will be displayed within the block.
|
|
|
|
final Widget? child;
|
|
|
|
|
|
|
|
/// The start hour of the timetable.
|
|
|
|
final int startHour;
|
|
|
|
|
2022-08-24 13:32:35 +02:00
|
|
|
/// The heigh of one hour in the timetable.
|
|
|
|
final double hourHeight;
|
|
|
|
|
2022-08-24 12:03:32 +02:00
|
|
|
/// The width of the block if there is no child
|
|
|
|
final double blockWidth;
|
|
|
|
|
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(
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top:
|
|
|
|
(((start.hour - startHour) * 60) + start.minute) * sizePerMinute() +
|
|
|
|
linePadding,
|
|
|
|
),
|
|
|
|
height: (((end.hour - start.hour) * 60) + end.minute - start.minute) *
|
|
|
|
sizePerMinute(),
|
|
|
|
child: child ??
|
|
|
|
Container(
|
|
|
|
height:
|
|
|
|
(((end.hour - start.hour) * 60) + end.minute - start.minute) *
|
|
|
|
sizePerMinute(),
|
|
|
|
width: blockWidth,
|
2022-08-24 13:32:35 +02:00
|
|
|
color: blockColor,
|
2022-08-24 12:03:32 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
double sizePerMinute() {
|
2022-08-24 13:32:35 +02:00
|
|
|
return hourHeight / 60;
|
2022-08-24 12:03:32 +02:00
|
|
|
}
|
|
|
|
}
|