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.
Capability-Based Design
Node capabilities are added via mixins:
- ResizableMixin - Resize functionality (sets isResizable to true)
- GroupableMixin - Grouping/container functionality with child node monitoring
Base nodes have port geometry built-in. Specialized nodes like GroupNode and CommentNode add capabilities through mixins.
Example
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
- GroupNode, a specialized node for grouping other nodes
- CommentNode, a specialized node for annotations
- Implementers
- Available extensions
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, bool visible = true, NodeRenderLayer layer = NodeRenderLayer.middle, bool locked = false, bool selectable = true}) - 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
- isEditing ↔ bool
-
Gets the current editing state.
getter/setter pair
- isResizable → bool
-
Whether this node can be resized.
no setter
- isSelected ↔ bool
-
Gets the current selection state.
getter/setter pair
- isVisible ↔ bool
-
Gets the current visibility state.
getter/setter pair
- layer → NodeRenderLayer
-
Rendering layer for this node.
final
- locked → bool
-
Whether this node is locked from user interactions.
final
-
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
- selectable → bool
-
Whether this node participates in marquee selection.
final
-
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 (may include snap-to-grid).
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.
-
buildWidget(
BuildContext context) → Widget? - Builds the widget for this node.
-
containsPoint(
Offset point) → 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(
) → Rect - Gets the node's bounding rectangle.
-
getConnectionPoint(
String portId, {required Size portSize, NodeShape? shape}) → Offset -
Available on Node<
Gets the connection attachment point for a port in graph coordinates.T> , provided by the NodePortGeometry extension -
getPortCapsuleSide(
String portId) → CapsuleFlatSide -
Available on Node<
Gets the capsule flat side orientation for a port.T> , provided by the NodePortGeometry extension -
getPortCenter(
String portId, {required Size portSize, NodeShape? shape}) → Offset -
Available on Node<
Gets the visual center of a port in graph coordinates.T> , provided by the NodePortGeometry extension -
getVisualPortOrigin(
String portId, {required Size portSize, NodeShape? shape}) → Offset -
Available on Node<
Gets the visual position where a port should be rendered within the node container.T> , provided by the NodePortGeometry extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDragEnd(
) → void - Called when a drag operation ends.
-
onDragMove(
Offset delta, NodeDragContext context) → void - Called during a drag operation as the node moves.
-
onDragStart(
NodeDragContext context) → void - Called when a drag operation starts on this node.
-
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.
-
setSize(
Size newSize) → void - Sets the size of this node.
-
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