attemptExpand method
Implementation
bool attemptExpand(int index, int direction, double delta) {
final item = items[index];
double currentSize = item.newValue; // check
double minSize = item.min;
double maxSize = item.max;
double newSize = currentSize + delta;
double minOverflow = newSize - minSize;
double maxOverflow = newSize - maxSize;
if (minOverflow < 0 && delta < 0) {
delta = delta - minOverflow;
}
if (maxOverflow > 0 && delta > 0) {
delta = delta - maxOverflow;
}
if (delta == 0) {
return false;
}
if (index == 0) {
direction = 1;
} else if (index == items.length - 1) {
direction = -1;
}
if (direction < 0) {
var borrowed = _borrowSize(index - 1, -delta, 0, -1);
if (borrowed.givenSize != -delta) {
reset();
return false;
}
item._newValue = (item.newValue + delta).clamp(minSize, maxSize);
// check
return true;
} else if (direction > 0) {
var borrowed = _borrowSize(index + 1, -delta, items.length - 1, 1);
if (borrowed.givenSize != -delta) {
reset();
return false;
}
item._newValue = (item.newValue + delta).clamp(minSize, maxSize);
// check
return true;
} else if (direction == 0) {
double halfDelta = delta / 2;
var borrowedLeft = _borrowSize(index - 1, -halfDelta, 0, -1);
var borrowedRight =
_borrowSize(index + 1, -halfDelta, items.length - 1, 1);
if (borrowedLeft.givenSize != -halfDelta ||
borrowedRight.givenSize != -halfDelta) {
reset();
return false;
}
item._newValue = (item.newValue + delta).clamp(minSize, maxSize);
// check
return true;
}
return false;
}