update method

  1. @mustCallSuper
void update(
  1. covariant Widget newWidget
)

Change the widget used to configure this element.

The framework calls this function when the parent wishes to use a different widget to configure this element. The new widget is guaranteed to have the same runtimeType as the old widget.

This function is called only during the "active" lifecycle state.

Implementation

@mustCallSuper
void update(covariant Widget newWidget) {
  // This code is hot when hot reloading, so we try to
  // only call _AssertionError._evaluateAssertion once.
  assert(
    _lifecycleState == _ElementLifecycle.active
      && newWidget != widget
      && Widget.canUpdate(widget, newWidget),
  );
  // This Element was told to update and we can now release all the global key
  // reservations of forgotten children. We cannot do this earlier because the
  // forgotten children still represent global key duplications if the element
  // never updates (the forgotten children are not removed from the tree
  // until the call to update happens)
  assert(() {
    _debugForgottenChildrenWithGlobalKey?.forEach(_debugRemoveGlobalKeyReservation);
    _debugForgottenChildrenWithGlobalKey?.clear();
    return true;
  }());
  _widget = newWidget;
}