activate method

  1. @override
  2. @mustCallSuper
void activate()
inherited

Called when this object is reinserted into the tree after having been removed via deactivate.

Implementation

@override
@mustCallSuper
void activate() {
  /// In most cases, after a [State] object has been deactivated, it is _not_
  /// reinserted into the tree, and its [dispose] method will be called to
  /// signal that it is ready to be garbage collected.
  ///
  /// In some cases, however, after a [State] object has been deactivated, the
  /// framework will reinsert it into another part of the tree (e.g., if the
  /// subtree containing this [State] object is grafted from one location in
  /// the tree to another due to the use of a [GlobalKey]).

  // Likely was deactivated.
  _deactivated = false;

  /// Become aware of Route changes
  RouteObserverStates.subscribeRoutes(this);

  // No 'setState()' functions are allowed to fully function at this point.
  //   _setStateAllowed = false;

  for (final con in controllerList) {
    if (con.lastState == null) {
      con.activate();
    }
    con._pushStateToSetter(this);
    con.activateState(this);
  }

  // Add to the list of StateX objects present in the app!
  _addToMapOfStates(this);

  // Optionally call super for debugPrint()
  super.activate();

  _setStateAllowed = true;

  // In some cases, if then reinserted back in another part of the tree
  // the build is called, and so setState() is not necessary.
  _setStateRequested = false;
}