of static method
Obtains the nearest Wildness instance from the BuildContext.
If listen is true (default), the widget will rebuild when the Wildness changes.
If listen is false, it will not rebuild, suitable for one-off reads.
Implementation
// ignore: prefer_constructors_over_static_methods
static Wildness of(BuildContext context, {bool listen = true}) {
final inheritedTheme = listen
? //searches only for InheritedWidget
context.dependOnInheritedWidgetOfExactType<WildnessProvider>()
: //does not establish a relationship with the target in the way that dependOnInheritedWidgetOfExactType does.
(context
.getElementForInheritedWidgetOfExactType<WildnessProvider>()
?.widget
as WildnessProvider?);
//expensive, searches for any Widget subclass
// context.findAncestorWidgetOfExactType<_InheritedWildnessTheme>();
//! No podemos retornar una excepción aquí, para permitir usar los componentes sueltos sin theme
return inheritedTheme?.data ??
const Wildness(
physics: AlwaysScrollableScrollPhysics(),
components: {},
resources: {},
);
}