get<T extends Object> method
T
get<T extends Object>()
Searches for a Bilocator widget with location
param set and a model of type T
.
usage:
final myService = context.get<MyService>();
The search is for the first match up the widget tree from the calling widget.
This does not set up a dependency between the InheritedWidget and the context. For that, use of.
Performs a lazy initialization if necessary. Throws exception of widget not found.
For those familiar with Provider, get is effectively Provider.of<MyModel>(listen: false);
.
Implementation
T get<T extends Object>() {
final inheritedWidget = _getInheritedWidget<T>();
return inheritedWidget.instance;
}