dependOnInheritedWidgetOfExactType<T extends InheritedWidget> method

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

Obtains the nearest inherited widget of the given type T.

Implementation

@override
T? dependOnInheritedWidgetOfExactType<T extends InheritedWidget>() {
  var ancestor = parent;
  while (ancestor != null) {
    if (ancestor.widget is T) {
      return ancestor.widget as T;
    }
    ancestor = ancestor.parent;
  }
  return null;
}