of<T extends Listenable> static method
Retrieves the Listenable object of type T from the nearest
InheritedProvider ancestor widget.
If listen is true, this widget will rebuild whenever the Listenable
changes. Otherwise, it will only retrieve the current value of the
Listenable and not rebuild when it changes.
Implementation
static T of<T extends Listenable>(BuildContext context,
{bool listen = false}) {
final parentInheritedWidget =
context.dependOnInheritedWidgetOfExactType<InheritedProvider<T>>();
assert(parentInheritedWidget != null,
'No change notifier found of type $T in context');
final element =
context.getElementForInheritedWidgetOfExactType<InheritedProvider<T>>();
if (element != null && listen) {
context.dependOnInheritedElement(element);
}
return parentInheritedWidget!.notifier!;
}