setNodePosition method

void setNodePosition(
  1. String nodeId,
  2. Offset position
)

Sets a node's position to an absolute position.

The position will be automatically snapped to the grid if snap-to-grid is enabled in the controller's configuration.

Does nothing if the node doesn't exist.

Parameters:

  • nodeId: The ID of the node to reposition
  • position: The new absolute position in graph coordinates

Example:

controller.setNodePosition('node1', Offset(200, 150));

Implementation

void setNodePosition(String nodeId, Offset position) {
  final node = _nodes[nodeId];
  if (node != null) {
    runInAction(() {
      node.position.value = position;
      // Update visual position with snapping
      node.setVisualPosition(_config.snapToGridIfEnabled(position));
    });
  }
}