attemptExpandCollapsed method
bool
attemptExpandCollapsed(
- int index,
- int direction
)
Implementation
bool attemptExpandCollapsed(int index, int direction) {
if (index == 0) {
direction = 1;
} else if (index == items.length - 1) {
direction = -1;
}
final item = items[index];
final collapsedSize = item.collapsedSize ?? 0;
final currentSize = item.newValue;
final delta = collapsedSize - currentSize;
if (direction < 0) {
var borrowed = _borrowSize(index - 1, delta, 0, -1);
if (borrowed.givenSize != delta) {
reset();
return false;
}
item._newCollapsed = false;
return true;
} else if (direction > 0) {
var borrowed = _borrowSize(index + 1, delta, items.length - 1, 1);
if (borrowed.givenSize != delta) {
reset();
return false;
}
item._newCollapsed = false;
return true;
} else if (direction == 0) {
final 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._newCollapsed = false;
return true;
}
return false;
}