updateControlPoint method
Updates the position of a control point on a connection.
This method is typically called during drag operations to move an existing control point to a new position.
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 updateposition: The new position of the control point in graph coordinates
Example:
// Move the first control point to a new position
controller.updateControlPoint('conn1', 0, Offset(180, 220));
Implementation
void updateControlPoint(String connectionId, int index, Offset position) {
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[index] = position;
connection.controlPoints = controlPoints;
});
// Invalidate cached path
_connectionPainter?.pathCache.removeConnection(connectionId);
}