deactivate method Null safety

  1. @mustCallSuper
void deactivate()

Transition from the "active" to the "inactive" lifecycle state.

The framework calls this method when a previously active element is moved to the list of inactive elements. While in the inactive state, the element will not appear on screen. The element can remain in the inactive state only until the end of the current animation frame. At the end of the animation frame, if the element has not be reactivated, the framework will unmount the element.

This is (indirectly) called by deactivateChild.

See the lifecycle documentation for Element for additional information.

Implementations of this method should end with a call to the inherited method, as in super.deactivate().

Implementation

@mustCallSuper
void deactivate() {
  assert(_lifecycleState == _ElementLifecycle.active);
  assert(_widget != null); // Use the private property to avoid a CastError during hot reload.
  assert(depth != null);
  if (_dependencies != null && _dependencies!.isNotEmpty) {
    for (final InheritedElement dependency in _dependencies!)
      dependency._dependents.remove(this);
    // For expediency, we don't actually clear the list here, even though it's
    // no longer representative of what we are registered with. If we never
    // get re-used, it doesn't matter. If we do, then we'll clear the list in
    // activate(). The benefit of this is that it allows Element's activate()
    // implementation to decide whether to rebuild based on whether we had
    // dependencies here.
  }
  _inheritedWidgets = null;
  _lifecycleState = _ElementLifecycle.inactive;
}