addNode method

void addNode(
  1. Node<T> node
)

Adds a new node to the graph.

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

Triggers the onNodeCreated callback after successful addition.

Example:

final node = Node<MyData>(
  id: 'node1',
  type: 'process',
  position: Offset(100, 100),
  data: MyData(),
);
controller.addNode(node);

Implementation

void addNode(Node<T> node) {
  runInAction(() {
    _nodes[node.id] = node;
    // Initialize visual position with snapping
    node.setVisualPosition(_config.snapToGridIfEnabled(node.position.value));
  });
  // Fire callback after successful addition
  callbacks.onNodeCreated?.call(node);
}