inflateComponent method

  1. @protected
Element inflateComponent(
  1. Component newComponent,
  2. Element? prevSibling
)

Create an element for the given component and add it as a child of this element.

This method is typically called by updateChild but can be called directly by subclasses that need finer-grained control over creating elements.

If the given component has a global key and an element already exists that has a component with that global key, this function will reuse that element (potentially grafting it from another location in the tree or reactivating it from the list of inactive elements) rather than creating a new element.

The element returned by this function will already have been mounted and will be in the "active" lifecycle state.

Implementation

@protected
Element inflateComponent(Component newComponent, Element? prevSibling) {
  final Key? key = newComponent.key;
  if (key is GlobalKey) {
    final Element? newChild = _retakeInactiveElement(key, newComponent);
    if (newChild != null) {
      assert(newChild._parent == null);
      newChild._activateWithParent(this);
      newChild._parentChanged = true;
      final Element? updatedChild = updateChild(newChild, newComponent, prevSibling);
      assert(newChild == updatedChild);
      return updatedChild!;
    }
  }
  final Element newChild = newComponent.createElement();
  newChild.mount(this, prevSibling);
  newChild.didMount();
  assert(newChild._lifecycleState == _ElementLifecycle.active);
  return newChild;
}