Connection class
Represents a visual connection between two ports on different nodes in a node flow diagram.
A Connection links a source port on one node to a target port on another node, creating a visual edge that can be styled, animated, and labeled. Connections are reactive and use MobX observables for state management.
Key Features
- Port-to-port linking: Connects specific ports between nodes
- Reactive state: Uses MobX observables for animated, selected, and label properties
- Customizable styling: Supports custom ConnectionStyle and ConnectionEndPoints
- Three label positions: Supports startLabel (anchor 0.0), label (anchor 0.5), and endLabel (anchor 1.0)
- Data attachment: Can carry arbitrary data via the data property
Usage Example
final connection = Connection(
id: 'conn-1',
sourceNodeId: 'node-a',
sourcePortId: 'output-1',
targetNodeId: 'node-b',
targetPortId: 'input-1',
startLabel: ConnectionLabel.start(text: 'Start'),
label: ConnectionLabel.center(text: 'Data Flow'),
endLabel: ConnectionLabel.end(text: 'End', offset: 10.0),
animated: true,
style: ConnectionStyles.smoothstep,
);
// Update labels directly
connection.label = ConnectionLabel.center(text: 'Updated Flow');
connection.startLabel = null; // Remove start label
// Check node/port involvement
if (connection.involvesNode('node-a')) {
print('Connection involves node-a');
}
Observable Properties
The following properties are reactive and will trigger UI updates when changed:
- animated: Whether the connection has flowing animation
- selected: Whether the connection is currently selected
- startLabel: Label at the start of the connection (anchor 0.0)
- label: Label at the center of the connection (anchor 0.5)
- endLabel: Label at the end of the connection (anchor 1.0)
See also:
- ConnectionLabel for label configuration
- ConnectionStyle for styling options
- ConnectionEndPoint for endpoint marker configuration
- NodeFlowController for managing connections in the flow
- Annotations
-
- @JsonSerializable.new()
Constructors
-
Connection({required String id, required String sourceNodeId, required String sourcePortId, required String targetNodeId, required String targetPortId, bool animated = false, bool selected = false, Map<
String, dynamic> ? data, ConnectionStyle? style, ConnectionLabel? startLabel, ConnectionLabel? label, ConnectionLabel? endLabel, ConnectionEndPoint? startPoint, ConnectionEndPoint? endPoint, ConnectionEffect? animationEffect}) - Creates a connection between two ports.
-
Connection.fromJson(Map<
String, dynamic> json) -
Creates a Connection from a JSON map.
factory
Properties
- animated ↔ bool
-
Whether the connection shows flowing animation.
getter/setter pair
- animationEffect ↔ ConnectionEffect?
-
The animation effect to apply to this connection.
getter/setter pair
-
data
→ Map<
String, dynamic> ? -
Optional arbitrary data to attach to the connection.
final
- endLabel ↔ ConnectionLabel?
-
The label at the end of the connection (anchor 1.0).
getter/setter pair
- endPoint → ConnectionEndPoint?
-
Optional custom end endpoint marker.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Unique identifier for this connection.
final
- label ↔ ConnectionLabel?
-
The label at the center of the connection (anchor 0.5).
getter/setter pair
-
labels
→ List<
ConnectionLabel> -
The list of all non-null labels displayed along the connection path.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selected ↔ bool
-
Whether the connection is currently selected.
getter/setter pair
- sourceNodeId → String
-
ID of the node containing the source port.
final
- sourcePortId → String
-
ID of the source port on the source node.
final
- startLabel ↔ ConnectionLabel?
-
The label at the start of the connection (anchor 0.0).
getter/setter pair
- startPoint → ConnectionEndPoint?
-
Optional custom start endpoint marker.
final
- style → ConnectionStyle?
-
Optional custom style override for this connection.
final
- targetNodeId → String
-
ID of the node containing the target port.
final
- targetPortId → String
-
ID of the target port on the target node.
final
Methods
-
dispose(
) → void - Disposes resources used by this connection.
-
getEffectiveAnimationEffect(
ConnectionEffect? themeAnimationEffect) → ConnectionEffect? - Gets the effective animation effect for rendering.
-
getEffectiveEndPoint(
ConnectionEndPoint themeEndPoint) → ConnectionEndPoint - Gets the effective end endpoint marker for rendering.
-
getEffectiveStartPoint(
ConnectionEndPoint themeStartPoint) → ConnectionEndPoint - Gets the effective start endpoint marker for rendering.
-
getEffectiveStyle(
ConnectionStyle themeStyle) → ConnectionStyle - Gets the effective connection style for rendering.
-
involvesNode(
String nodeId) → bool - Checks if this connection involves the given node.
-
involvesPort(
String nodeId, String portId) → bool - Checks if this connection involves the given port on a specific node.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts this Connection to a JSON map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited