sendNodeBackward method
Moves a node one step backward in the z-order.
Swaps the z-index with the next lower node in the visual stack.
Implementation
void sendNodeBackward(String nodeId) {
final node = _nodes[nodeId];
if (node == null) return;
runInAction(() {
final sortedNodes = _nodes.values.toList()
..sort((a, b) => a.zIndex.value.compareTo(b.zIndex.value));
final currentIndex = sortedNodes.indexOf(node);
if (currentIndex > 0) {
final prevNode = sortedNodes[currentIndex - 1];
if (node.zIndex.value == prevNode.zIndex.value) {
for (int i = 0; i < sortedNodes.length; i++) {
sortedNodes[i].zIndex.value = i;
}
node.zIndex.value = currentIndex - 1;
prevNode.zIndex.value = currentIndex;
} else {
final currentZ = node.zIndex.value;
final prevZ = prevNode.zIndex.value;
node.zIndex.value = prevZ;
prevNode.zIndex.value = currentZ;
}
}
});
}