requestDeleteNode method
Requests deletion of a node with lock check and confirmation callback.
This async method:
- Checks if deletion is allowed by current behavior
- Checks if the node is locked (returns false if locked)
- Calls
onBeforeNodeDeletecallback if provided (returns false if vetoed) - Removes the node if all checks pass
Use this method when you want to respect locks and confirmation dialogs. For direct removal without checks, use removeNode instead.
Returns true if the node was deleted, false if deletion was prevented.
Example:
final deleted = await controller.requestDeleteNode('node1');
if (!deleted) {
print('Node deletion was prevented');
}
Implementation
Future<bool> requestDeleteNode(String nodeId) async {
// Check behavior first
if (!behavior.canDelete) return false;
final node = _nodes[nodeId];
if (node == null) return false;
// Check if node is locked
if (node.locked) return false;
// Call before-delete callback if provided
final callback = events.node?.onBeforeDelete;
if (callback != null) {
final allowed = await callback(node);
if (!allowed) return false;
}
// Proceed with deletion
removeNode(nodeId);
return true;
}