inheritFromElement method

  1. @override
InheritedWidget inheritFromElement (InheritedElement ancestor, { Object aspect })
override

Registers this build context with ancestor such that when ancestor's widget changes this build context is rebuilt.

Returns ancestor.widget.

This method is rarely called directly. Most applications should use inheritFromWidgetOfExactType, which calls this method after finding the appropriate InheritedElement ancestor.

All of the qualifications about when inheritFromWidgetOfExactType can be called apply to this method as well.

Implementation

@override
InheritedWidget inheritFromElement(InheritedElement ancestor, { Object aspect }) {
  assert(ancestor != null);
  _dependencies ??= HashSet<InheritedElement>();
  _dependencies.add(ancestor);
  ancestor.updateDependencies(this, aspect);
  return ancestor.widget;
}