updateDependencies method
override
Called by dependOnInheritedWidgetOfExactType when a new dependent
is added.
Each dependent element can be mapped to a single object value with setDependencies. This method can lookup the existing dependencies with getDependencies.
By default this method sets the inherited dependencies for dependent
to null. This only serves to record an unconditional dependency on
dependent
.
Subclasses can manage their own dependencies values so that they can selectively rebuild dependents in notifyDependent.
See also:
- getDependencies, which returns the current value for a dependent element.
- setDependencies, which sets the value for a dependent element.
- notifyDependent, which can be overridden to use a dependent's dependencies value to decide if the dependent needs to be rebuilt.
- InheritedModel, which is an example of a class that uses this method to manage dependency values.
Implementation
@override
void updateDependencies(Element dependent, Object? aspect) {
final Set<T>? dependencies = getDependencies(dependent) as Set<T>?;
if (dependencies != null && dependencies.isEmpty) {
return;
}
if (aspect == null) {
setDependencies(dependent, HashSet<T>());
} else {
assert(aspect is T);
setDependencies(dependent, (dependencies ?? HashSet<T>())..add(aspect as T));
}
}