of static method
Obtains the nearest Provider<T>
up its widget tree and returns its
value.
If listen
is true
, later value changes will trigger a new
State.build to widgets, and State.didChangeDependencies for
StatefulWidget.
listen: false
is necessary to be able to call Provider.of
inside
State.initState or the create
method of providers like so:
Provider(
create: (context) {
return Model(Provider.of<Something>(context, listen: false)),
},
)
Implementation
static GlobalRouteObserver of(BuildContext context) => Provider.of(
context,
listen: false,
);