inheritFrom< T extends InheritedModel< Object>> method
Makes context
dependent on the specified aspect
of an InheritedModel
of type T.
When the given aspect
of the model changes, the context
will be
rebuilt. The updateShouldNotifyDependent method must determine if a
change in the model widget corresponds to an aspect
value.
The dependencies created by this method target all InheritedModel ancestors of type T up to and including the first one for which isSupportedAspect returns true.
If aspect
is null this method is the same as
context.inheritFromWidgetOfExactType(T)
.
Implementation
static T inheritFrom<T extends InheritedModel<Object>>(BuildContext context, { Object aspect }) {
if (aspect == null)
return context.inheritFromWidgetOfExactType(T);
// Create a dependency on all of the type T ancestor models up until
// a model is found for which isSupportedAspect(aspect) is true.
final List<InheritedElement> models = _findModels<T>(context, aspect).toList();
final InheritedElement lastModel = models.last;
for (InheritedElement model in models) {
final T value = context.inheritFromElement(model, aspect: aspect);
if (model == lastModel)
return value;
}
assert(false);
return null;
}