updateDependencies method

  1. @override
void updateDependencies (Element dependent, Object aspect)

Called by inheritFromWidgetOfExactType 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 notifyDependents.

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.


void updateDependencies(Element dependent, Object aspect) {
  final Set<T> dependencies = getDependencies(dependent);
  if (dependencies != null && dependencies.isEmpty)

  if (aspect == null) {
    setDependencies(dependent, HashSet<T>());
  } else {
    assert(aspect is T);
    setDependencies(dependent, (dependencies ?? HashSet<T>())..add(aspect));