findAncestorWidgetOfExactType<T extends Widget> method

  1. @override
T? findAncestorWidgetOfExactType<T extends Widget>()
inherited

The widget of the nearest ancestor whose widget is exactly a T.

Implementation

@override
T? findAncestorWidgetOfExactType<T extends Widget>() {
  for (var a = _parent; a != null; a = a._parent) {
    final widget = a.widget;
    if (widget.runtimeType == T) {
      return widget as T;
    }
  }
  return null;
}