getTimeAtPos method
Implementation
PlannerTime getTimeAtPos(Offset pos) {
Offset realPos = _toGridPos(pos);
// Clamp to valid ranges so taps above/left of the grid (negative) or past
// the last column/hour (grid smaller than the viewport) can't produce an
// out-of-range day/hour.
int day = (realPos.dx / config.blockWidth)
.floor()
.clamp(0, config.labels.length - 1);
// Row index from the top of the grid, plus the proportional minute offset
// into that row (pixels -> minutes via blockHeight, not a hardcoded 40),
// snapped to the configured interval so a created event lands on the same
// grid a dragged one does.
final double rawRow = realPos.dy / config.blockHeight;
final int row = rawRow.floor();
int hour = config.minHour + row;
int minutes = snapToInterval(((rawRow - row) * 60).floor());
// A tap outside the grid clamps to a valid hour; its minute offset is
// meaningless, so pin it to the hour boundary.
if (hour < config.minHour) {
hour = config.minHour;
minutes = 0;
} else if (hour > config.maxHour) {
hour = config.maxHour;
minutes = 0;
}
return PlannerTime(day: day, hour: hour, minutes: minutes);
}