dragDivider method

void dragDivider(
  1. int index,
  2. double delta
)

Implementation

void dragDivider(int index, double delta) {
  if (delta == 0) {
    return;
  }

  var borrowedLeft = _borrowSize(index - 1, delta, 0, -1);
  var borrowedRight = _borrowSize(index, -delta, items.length - 1, 1);

  double borrowedRightSize = borrowedRight.givenSize;
  double borrowedLeftSize = borrowedLeft.givenSize;

  double couldNotBorrowRight = borrowedRightSize + delta;
  double couldNotBorrowLeft = borrowedLeftSize - delta;

  if (couldNotBorrowLeft != 0 || couldNotBorrowRight != 0) {
    _couldNotBorrow += delta;
  } else {
    _couldNotBorrow = 0;
  }

  double givenBackLeft = 0;
  double givenBackRight = 0;

  if (couldNotBorrowLeft != -couldNotBorrowRight) {
    givenBackLeft =
        _borrowSize(borrowedRight.from, -couldNotBorrowLeft, index, -1)
            .givenSize;
    givenBackRight =
        _borrowSize(borrowedLeft.from, -couldNotBorrowRight, index - 1, 1)
            .givenSize;
  }

  if (givenBackLeft != -couldNotBorrowLeft ||
      givenBackRight != -couldNotBorrowRight) {
    reset();
    return;
  }

  double payOffLeft = _payOffLoanSize(index - 1, delta, -1);
  double payOffRight = _payOffLoanSize(index, -delta, 1);

  double payingBackLeft =
      _borrowSize(index - 1, -payOffLeft, 0, -1).givenSize;
  double payingBackRight =
      _borrowSize(index, -payOffRight, items.length - 1, 1).givenSize;

  if (payingBackLeft != -payOffLeft || payingBackRight != -payOffRight) {
    reset();
    return;
  }

  if (_couldNotBorrow > 0) {
    int start = borrowedRight.from;
    int endNotCollapsed = items.length - 1;
    for (int i = endNotCollapsed; i > start; i--) {
      if (items[i].newCollapsed) {
        endNotCollapsed = i - 1;
      } else {
        break;
      }
    }
    if (start == endNotCollapsed) {
      _checkCollapseUntil(index);
    }
    _checkExpanding(index);
  } else if (_couldNotBorrow < 0) {
    int start = borrowedLeft.from;
    int endNotCollapsed = 0;
    for (int i = endNotCollapsed; i < start; i++) {
      if (items[i].newCollapsed) {
        endNotCollapsed = i + 1;
      } else {
        break;
      }
    }
    if (start == endNotCollapsed) {
      _checkCollapseUntil(index);
    }
    _checkExpanding(index);
  }
}