findAncestorElementOfExactType<T extends InheritedWidget> method

InheritedElement? findAncestorElementOfExactType<T extends InheritedWidget>()

Returns the nearest InheritedElement of type T.

Implementation

InheritedElement?
    findAncestorElementOfExactType<T extends InheritedWidget>() {
  Element? current = _parent;
  while (current != null) {
    if (current.widget is T && current is InheritedElement) {
      return current;
    }
    current = current._parent;
  }
  return null;
}