containerOf static method
Read the current ProviderContainer for a BuildContext.
Implementation
static ProviderContainer containerOf(
BuildContext context, {
bool listen = true,
}) {
_UncontrolledProviderScope? scope;
if (listen) {
scope =
context //
.dependOnInheritedWidgetOfExactType<_UncontrolledProviderScope>();
} else {
scope =
context
.getElementForInheritedWidgetOfExactType<
_UncontrolledProviderScope
>()
?.widget
as _UncontrolledProviderScope?;
}
if (scope == null) {
throw StateError('No ProviderScope found');
}
return scope.container;
}