getPortCapsuleSide method

CapsuleFlatSide getPortCapsuleSide(
  1. String portId
)

Gets the capsule flat side orientation for a port.

Ports are rendered as capsule half shapes with one flat edge. This method determines which edge should be flat based on the port's position.

Parameters:

  • portId - The unique identifier of the port

Returns the CapsuleFlatSide orientation for the port.

Throws ArgumentError if no port with the given portId is found.

Implementation

CapsuleFlatSide getPortCapsuleSide(String portId) {
  final port = [
    ...inputPorts,
    ...outputPorts,
  ].cast<Port?>().firstWhere((p) => p?.id == portId, orElse: () => null);

  if (port == null) {
    throw ArgumentError('Port $portId not found');
  }

  switch (port.position) {
    case PortPosition.left:
      return CapsuleFlatSide.left;
    case PortPosition.right:
      return CapsuleFlatSide.right;
    case PortPosition.top:
      return CapsuleFlatSide.top;
    case PortPosition.bottom:
      return CapsuleFlatSide.bottom;
  }
}