attach method

  1. @override
Future attach(
  1. Portal<Object?>? portal
)
override

Attaches portal.

Returns a future that completes when portal is attached with the context of the instantiated view. For components, this is an instance of the component. For views, it is a Map of locals.

When possible, prefer using Portal.attach, as it returns a typed result instead of dynamic.

Implementation

@override
Future<dynamic /*ComponentRef<Object> | Map<String, dynamic>*/ > attach(
    Portal<Object?>? portal) {
  //assert(portal != null);
  if (_isDisposed) {
    throw StateError('Already disposed.');
  }
  if (hasAttached) {
    throw StateError('Already has attached portal!');
  }
  if (portal is ComponentPortal<Object>) {
    _attachedPortal = portal;
    portal.setAttachedHost(this);
    return attachComponentPortal(portal);
  } else if (portal is TemplatePortal) {
    _attachedPortal = portal;
    portal.setAttachedHost(this);
    return attachTemplatePortal(portal);
  } else if (portal == null) {
    throw ArgumentError.notNull('portal');
  } else {
    throw ArgumentError.value(portal, 'portal');
  }
}