addControlPoint method
Adds a control point to a connection at the specified position.
Control points are intermediate waypoints that define the path of editable connections. The new control point is inserted at the given index in the control points list.
Example:
// Add a control point at the end
controller.addControlPoint('conn1', Offset(150, 200));
// Insert a control point at a specific index
controller.addControlPoint('conn1', Offset(100, 150), index: 0);
Implementation
void addControlPoint(String connectionId, Offset position, {int? index}) {
final connection = _connections.firstWhere(
(c) => c.id == connectionId,
orElse: () => throw ArgumentError('Connection $connectionId not found'),
);
runInAction(() {
final controlPoints = List<Offset>.from(connection.controlPoints);
if (index != null && index >= 0 && index <= controlPoints.length) {
controlPoints.insert(index, position);
} else {
controlPoints.add(position);
}
connection.controlPoints = controlPoints;
});
// Invalidate cached path and rebuild spatial index
_connectionPainter?.pathCache.removeConnection(connectionId);
_rebuildSingleConnectionSpatialIndex(connection);
}