ancestorInheritedElementForWidgetOfExactType method

InheritedElement ancestorInheritedElementForWidgetOfExactType (Type targetType)

Obtains the element corresponding to the nearest widget of the given type, which must be the type of a concrete InheritedWidget subclass.

Calling this method is O(1) with a small constant factor.

This method does not establish a relationship with the target in the way that inheritFromWidgetOfExactType does.

This method should not be called from State.dispose because the element tree is no longer stable at that time. To refer to an ancestor from that method, save a reference to the ancestor by calling inheritFromWidgetOfExactType in State.didChangeDependencies. It is safe to use this method from State.deactivate, which is called whenever the widget is removed from the tree.


InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType);