onRemoved method Null safety

  1. @override
  2. @mustCallSuper
void onRemoved()
@mustCallSuper, inherited

When a component has been removed from the Core Context, we clean up any dangling references left on the parent and on any other dependent component. It's important for specialization of Component to respond to override onDependencyRemoved and clean up any further stored references to that component (for example the target of a Constraint).

Implementation

@override
@mustCallSuper
void onRemoved() {
  super.onRemoved();
  for (final parentDep in _dependsOn) {
    parentDep._dependents.remove(this);
  }
  _dependsOn.clear();

  for (final dependent in _dependents) {
    dependent.onDependencyRemoved(this);
  }
  _dependents.clear();

  // silently clear from the parent in order to not cause any further undo
  // stack changes
  if (parent != null) {
    parent!.children.remove(this);
    parent!.childRemoved(this);
  }

  // The artboard containing this component will need its dependencies
  // re-sorted.

  if (artboard != null) {
    context.markDependencyOrderDirty();
    _changeArtboard(null);
  }
}