resizeRowBorder method

double resizeRowBorder(
  1. int previousRow,
  2. int nextRow,
  3. double deltaHeight
)

Resizes adjacent rows by dragging their shared border.

Parameters:

  • previousRow (int, required): Index of row before border.
  • nextRow (int, required): Index of row after border.
  • deltaHeight (double, required): Height change in pixels.

Returns: double — actual height change applied.

Implementation

double resizeRowBorder(int previousRow, int nextRow, double deltaHeight) {
  if (previousRow < 0 || nextRow < 0 || deltaHeight == 0) {
    return 0;
  }
  // make sure that both previous and next row have height enough to resize
  var previousHeight = _rowHeights?[previousRow] ?? _defaultRowHeight;
  double newPreviousHeight = previousHeight + deltaHeight;
  var nextHeight = _rowHeights?[nextRow] ?? _defaultRowHeight;
  double newNextHeight = nextHeight - deltaHeight;
  double clampedPreviousHeight = newPreviousHeight.clamp(
      _heightConstraints?[previousRow]?.min ??
          _defaultHeightConstraint?.min ??
          0,
      _heightConstraints?[previousRow]?.max ??
          _defaultHeightConstraint?.max ??
          double.infinity);
  double clampedNextHeight = newNextHeight.clamp(
      _heightConstraints?[nextRow]?.min ?? _defaultHeightConstraint?.min ?? 0,
      _heightConstraints?[nextRow]?.max ??
          _defaultHeightConstraint?.max ??
          double.infinity);
  double previousDelta = clampedPreviousHeight - previousHeight;
  double nextDelta = clampedNextHeight - nextHeight;
  // find the delta that can be applied to both rows
  double delta = _absClosestTo(previousDelta, -nextDelta, 0);

  newPreviousHeight = previousHeight + delta;
  newNextHeight = nextHeight - delta;
  _rowHeights ??= {};
  _rowHeights![previousRow] = newPreviousHeight;
  _rowHeights![nextRow] = newNextHeight;
  notifyListeners();
  return delta;
}