getVisualPortOrigin method
Gets the visual position where a port should be rendered within the node container.
Gets the visual origin (top-left corner) of a port within this node's local coordinate space.
The origin is where the port widget's top-left corner should be positioned. Port widgets are positioned so their outer edge aligns with the node boundary.
Parameters:
portId- The unique identifier of the portportSize- The size of the port widget (width x height)shape- Optional shape for anchor-based positioning
Returns the Offset where the port widget's top-left corner should be positioned.
Throws ArgumentError if no port with the given portId is found.
See also:
- getConnectionPoint for the connection attachment position
- getPortCenter for the visual center position
Implementation
Offset getVisualPortOrigin(
String portId, {
required Size portSize,
NodeShape? shape,
}) {
final port = [
...inputPorts,
...outputPorts,
].cast<Port?>().firstWhere((p) => p?.id == portId, orElse: () => null);
if (port == null) {
throw ArgumentError('Port $portId not found');
}
// Get anchor position from shape (full node size) or default edge centers
final Offset anchorOffset;
if (shape != null) {
final anchors = shape.getPortAnchors(size.value);
final anchor = anchors.firstWhere(
(a) => a.position == port.position,
orElse: () => _fallbackAnchor(port.position),
);
anchorOffset = anchor.offset;
} else {
anchorOffset = _fallbackAnchor(port.position).offset;
}
// Use centralized calculation from PortPosition extension
return port.position.calculateOrigin(
anchorOffset: anchorOffset,
portSize: portSize,
portAdjustment: port.offset,
useAnchorForPerpendicularAxis: shape != null,
);
}