removeConnection method
Removes a connection from the graph.
Also removes the connection from the selection set if it was selected.
Triggers the onConnectionDeleted callback after successful removal.
Parameters:
connectionId: The ID of the connection to remove
Throws ArgumentError if the connection doesn't exist.
Implementation
void removeConnection(String connectionId) {
final connectionToDelete = _connections.firstWhere(
(c) => c.id == connectionId,
orElse: () => throw ArgumentError('Connection $connectionId not found'),
);
runInAction(() {
_connections.removeWhere((c) => c.id == connectionId);
_selectedConnectionIds.remove(connectionId);
});
// Remove cached path to prevent stale rendering
_connectionPainter?.removeConnectionFromCache(connectionId);
// Fire callback after successful removal
callbacks.onConnectionDeleted?.call(connectionToDelete);
}