findAncestorElementOfWidgetType<T extends Widget> static method

Element? findAncestorElementOfWidgetType<T extends Widget>(
  1. Element? element
)

Implementation

static Element? findAncestorElementOfWidgetType<T extends Widget>(Element? element) {
  if (element == null) {
    return null;
  }

  Element? target;
  element.visitAncestorElements((parent) {
    if (parent.widget is T) {
      target = parent;
      return false;
    }
    return true;
  });
  return target;
}