onBeforeStartConnection property

ConnectionValidationResult Function(ConnectionStartContext<T> context)? onBeforeStartConnection
final

Validation callback called before starting a connection from a port.

Return a ConnectionValidationResult to control whether the connection can be started. Set allowed: false to prevent the connection.

Example:

onBeforeStartConnection: (context) {
  // Don't allow connections from ports that already have connections
  if (context.existingConnections.isNotEmpty && !context.sourcePort.multiConnections) {
    return ConnectionValidationResult(
      allowed: false,
      message: 'Port already has a connection',
    );
  }
  return ConnectionValidationResult(allowed: true);
}

Implementation

final ConnectionValidationResult Function(ConnectionStartContext<T> context)?
onBeforeStartConnection;