mount method

  1. @mustCallSuper
void mount (Element parent, dynamic newSlot)
@mustCallSuper

Add this element to the tree in the given slot of the given parent.

The framework calls this function when a newly created element is added to the tree for the first time. Use this method to initialize state that depends on having a parent. State that is independent of the parent can more easily be initialized in the constructor.

This method transitions the element from the "initial" lifecycle state to the "active" lifecycle state.

Implementation

@mustCallSuper
void mount(Element parent, dynamic newSlot) {
  assert(_debugLifecycleState == _ElementLifecycle.initial);
  assert(widget != null);
  assert(_parent == null);
  assert(parent == null || parent._debugLifecycleState == _ElementLifecycle.active);
  assert(slot == null);
  assert(depth == null);
  assert(!_active);
  _parent = parent;
  _slot = newSlot;
  _depth = _parent != null ? _parent.depth + 1 : 1;
  _active = true;
  if (parent != null) // Only assign ownership if the parent is non-null
    _owner = parent.owner;
  if (widget.key is GlobalKey) {
    final GlobalKey key = widget.key;
    key._register(this);
  }
  _updateInheritance();
  assert(() { _debugLifecycleState = _ElementLifecycle.active; return true; }());
}