handleMultipleCollisionsForward function
void
handleMultipleCollisionsForward({
- required int dragOrderId,
- required int collisionOrderId,
- required Map<
int, GridItemEntity> childrenIdMap, - required List<
int> lockedChildren, - required ReorderCallback onReorder,
Called when the item changes his position between more than one item.
After the user drags the item with the given dragOrderId
to another
position under the current item and there would be more than one update of
the positions, then this method should be called.
It loops over all items that are between dragOrderId
and
collisionOrderId
and handles every collision of them.
The Map childrenOrderIdMap
is important to improve the performance for
searching children with a specific orderId.
There is no return value because childrenIdMap
and childrenOrderIdMap
gets immediately updated.
Implementation
void handleMultipleCollisionsForward({
required int dragOrderId,
required int collisionOrderId,
required Map<int, GridItemEntity> childrenIdMap,
required List<int> lockedChildren,
required ReorderCallback onReorder,
}) {
for (int i = dragOrderId; i < collisionOrderId; i++) {
int currentDragOrderId = i;
int foundCollisionOrderId = i + 1;
// look for the next child that has a collision
if (lockedChildren.contains(foundCollisionOrderId)) {
while (i + 2 <= collisionOrderId &&
lockedChildren.contains(foundCollisionOrderId)) {
foundCollisionOrderId = i + 2;
i++;
}
}
if (foundCollisionOrderId <= collisionOrderId) {
handleOneCollision(
dragOrderId: currentDragOrderId,
collisionOrderId: foundCollisionOrderId,
childrenIdMap: childrenIdMap,
lockedChildren: lockedChildren,
onReorder: onReorder,
);
}
}
}