handleMultipleCollisionsBackward function
void
handleMultipleCollisionsBackward({})
Called when the item changes his position between more than one item.
After the user drags the item with the given dragItemOrderId
to another
position above 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 dragItemOrderId
and
collisionItemOrderId
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 handleMultipleCollisionsBackward({
required int dragItemOrderId,
required int collisionItemOrderId,
required Map<int, GridItemEntity> childrenIdMap,
required Map<int, GridItemEntity> childrenOrderIdMap,
required List<int> lockedChildren,
void Function(int oldIndex, int newIndex)? onUpdate,
}) {
for (int i = dragItemOrderId; i > collisionItemOrderId; i--) {
int? dragId = childrenOrderIdMap[i]?.id;
int? collisionId = childrenOrderIdMap[i - 1]?.id;
if (lockedChildren.contains(collisionId)) {
while (i - 2 >= collisionItemOrderId &&
lockedChildren.contains(collisionId)) {
collisionId = childrenOrderIdMap[i - 2]?.id;
i--;
}
}
if (dragId != null && collisionId != null) {
handleOneCollision(
dragId: dragId,
collisionId: collisionId,
childrenIdMap: childrenIdMap,
childrenOrderIdMap: childrenOrderIdMap,
lockedChildren: lockedChildren,
onUpdate: onUpdate,
);
}
}
}