getNextCoordinate method

IntVector2 getNextCoordinate({
  1. required IntVector2 originalCoordinate,
  2. required AxisDirection direction,
})

Given a IntVector2 and a AxisDirection return the next coordinate that is not hidden.

Implementation

IntVector2 getNextCoordinate({
  required IntVector2 originalCoordinate,
  required AxisDirection direction,
}) {
  final axis = axisDirectionToAxis(direction);
  final headerController =
      parent.tableDataController.getHeaderControllerFor(axis: axis);
  var newCoordinate = originalCoordinate;

  bool shouldContinueLookup(IntVector2 curr) {
    final value = axis == Axis.vertical ? curr.dy : curr.dx;
    final headerData = headerController.value.customSizedHeaders[value];
    return headerData?.hidden == true;
  }

  // Iteratively move the current coordinate until [shouldContinueLookup]
  // finds the a suitable coordinate.
  do {
    newCoordinate += _moveVectors[direction]!;
    newCoordinate = IntVector2(
      axis == Axis.horizontal ? max(0, newCoordinate.dx) : newCoordinate.dx,
      axis == Axis.vertical ? max(0, newCoordinate.dy) : newCoordinate.dy,
    );
  } while (shouldContinueLookup(newCoordinate));

  return newCoordinate;
}