removeControlPoint method
Removes a control point from a connection.
Deletes the control point at the specified index. If this results in an empty control points list, the connection will revert to using its default algorithmic path.
Automatically invalidates the connection's cached path to trigger a repaint.
Does nothing if the connection doesn't exist or if the index is out of bounds.
Parameters:
connectionId: The ID of the connection to modifyindex: The index of the control point to remove
Example:
// Remove the second control point
controller.removeControlPoint('conn1', 1);
Implementation
void removeControlPoint(String connectionId, int index) {
final connection = _connections.firstWhere(
(c) => c.id == connectionId,
orElse: () => throw ArgumentError('Connection $connectionId not found'),
);
if (index < 0 || index >= connection.controlPoints.length) {
return; // Invalid index
}
runInAction(() {
final controlPoints = List<Offset>.from(connection.controlPoints);
controlPoints.removeAt(index);
connection.controlPoints = controlPoints;
});
// Invalidate cached path
_connectionPainter?.pathCache.removeConnection(connectionId);
}