Grid constructor

Grid({
  1. required Manager manager,
})

Implementation

Grid({required this.manager}) {
  final config = manager.config;
  final highlighted = config.highlightedColumn;
  if (highlighted != null &&
      highlighted >= 0 &&
      highlighted < config.labels.length) {
    highlightColumn = highlighted;
    highlightPaint = Paint()
      ..color = config.highlightColumnColor
      ..style = PaintingStyle.fill;
  }

  // vertical lines: drawn after each day
  Offset vstart = Offset(manager.config.blockWidth.toDouble(), 0);
  Offset vend = Offset(
      manager.config.blockWidth.toDouble(),
      manager.config.blockHeight.toDouble() *
          (manager.config.maxHour - manager.config.minHour + 1));
  for (int i = 0; i < manager.config.labels.length; i++) {
    vLines
        .add(Line(start: vstart, end: vend, controller: manager.controller));
    vstart = vstart.translate(manager.config.blockWidth.toDouble(), 0);
    vend = vend.translate(manager.config.blockWidth.toDouble(), 0);
  }

  // horizontal lines: for every 15 minutes, but only drawn if zoomed out
  double step = manager.config.blockHeight.toDouble() /
      4; // vSize stands for one hour, so this step is 15 minutes

  // this is the position for the first line
  Offset hstart = Offset(0, step);
  Offset hend = Offset(
      (manager.config.blockWidth.toDouble() * (manager.config.labels.length)),
      step);
  int lines = (manager.config.maxHour - manager.config.minHour + 1) * 4;

  for (int i = 0; i < lines; i++) {
    hLines
        .add(Line(start: hstart, end: hend, controller: manager.controller));
    // increase for next 15 minute line
    hstart = hstart.translate(0, step);
    hend = hend.translate(0, step);
  }

  hPaint = Paint()
    ..color = manager.config.horizontalLineColor
    ..style = PaintingStyle.stroke
    ..strokeWidth = 1;

  vPaint = Paint()
    ..color = manager.config.verticalLineColor
    ..style = PaintingStyle.stroke
    ..strokeWidth = 1;
}