dependOnInheritedWidgetOfExactType<T extends InheritedWidget> method

  1. @override
T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>()
inherited

The nearest InheritedWidget of exactly the type T above this context (or the context's own widget), found in constant time; null if there is none.

The context depends on it from then on: when it is replaced by one whose InheritedWidget.updateShouldNotify is true, the element is told in Element.didChangeDependencies and rebuilt. The dependency lasts until a later build of the element (its updateRenderObject, for a RenderObjectWidget) does not ask for it again, or one asked for in State.didChangeDependencies until a later call of it does not, or until the element leaves the tree. Not to be called in State.initState.

Implementation

@override
T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>() {
  final ancestor = _inheritedElements?[T];
  return ancestor == null ? null : dependOnInheritedElement(ancestor) as T;
}