Node<T> class

Represents a single node in the flow graph.

A node is a visual element that can be connected to other nodes via Ports. Each node has a position, size, and custom data of type T. Nodes can be dragged, selected, and connected to create complex flow diagrams.

The node system uses MobX observables for reactive updates, ensuring that any changes to node properties automatically trigger UI updates.

Example usage:

final node = Node<MyData>(
  id: 'node-1',
  type: 'processor',
  position: Offset(100, 100),
  data: MyData(value: 'example'),
  inputPorts: [
    Port(id: 'in-1', position: PortPosition.left),
  ],
  outputPorts: [
    Port(id: 'out-1', position: PortPosition.right),
  ],
);

See also:

  • Port, which defines connection points on nodes
  • NodeWidget, which renders nodes in the UI
  • NodeData, the interface for node data objects

Constructors

Node({required String id, required String type, required Offset position, required T data, Size? size, List<Port> inputPorts = const [], List<Port> outputPorts = const [], int initialZIndex = 0})
Creates a new node with the specified properties.
Node.fromJson(Map<String, dynamic> json, T fromJsonT(Object? json))
Creates a node from JSON data.
factory

Properties

allPorts List<Port>
Gets all ports (input and output combined).
no setter
currentZIndex int
Gets the current z-index value.
getter/setter pair
data → T
Custom data associated with this node.
final
dragging → Observable<bool>
Observable dragging state.
final
hashCode int
The hash code for this object.
no setterinherited
id String
Unique identifier for this node.
final
inputPorts → ObservableList<Port>
Observable list of input ports for incoming connections.
final
isDragging bool
Gets the current dragging state.
getter/setter pair
isSelected bool
Gets the current selection state.
getter/setter pair
outputPorts → ObservableList<Port>
Observable list of output ports for outgoing connections.
final
position → Observable<Offset>
Observable position of the node in graph coordinates.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selected → Observable<bool>
Observable selection state.
final
size → Observable<Size>
Observable size of the node.
final
type String
Type classification for this node.
final
visualPosition → Observable<Offset>
Observable visual position for rendering.
final
zIndex → Observable<int>
Observable z-index for stacking order.
final

Methods

addInputPort(Port port) → void
Adds an input port to the node.
addOutputPort(Port port) → void
Adds an output port to the node.
containsPoint(Offset point, {double portSize = 11.0}) bool
Checks if a point is within the node's rectangular bounds.
dispose() → void
Disposes of resources used by this node.
findPort(String portId) Port?
Finds a port by ID in either input or output ports.
getBounds({double portSize = 11.0}) Rect
Gets the node's bounding rectangle.
getPortCapsuleSide(String portId) CapsuleFlatSide
Gets the capsule flat side orientation for a port.
getPortPosition(String portId, {required double portSize, EdgeInsets? padding, NodeShape? shape}) Offset
Gets the connection point for a port where line endpoints should attach.
getVisualPortPosition(String portId, {required double portSize, EdgeInsets padding = EdgeInsets.zero, NodeShape? shape}) Offset
Gets the visual position where a port should be rendered within the node container.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeInputPort(String portId) bool
Removes an input port by ID.
removeOutputPort(String portId) bool
Removes an output port by ID.
removePort(String portId) bool
Removes a port by ID from either input or output ports.
setVisualPosition(Offset snappedPosition) → void
Updates the visual position based on the actual position and snapping rules.
toJson(Object? toJsonT(T value)) Map<String, dynamic>
Converts the node to a JSON map.
toString() String
A string representation of this object.
inherited
updateInputPort(String portId, Port updatedPort) bool
Updates an existing input port by ID.
updateOutputPort(String portId, Port updatedPort) bool
Updates an existing output port by ID.
updatePort(String portId, Port updatedPort) bool
Updates a port by ID in either input or output ports.

Operators

operator ==(Object other) bool
The equality operator.
inherited