attach method Null safety

  1. @override
void attach(
  1. covariant SemanticsOwner owner
)
override

Mark this node as attached to the given owner.

Typically called only from the parent's attach method, and by the owner to mark the root of a tree as attached.

Subclasses with children should override this method to first call their inherited attach method, and then attach all their children to the same owner.

Implementations of this method should start with a call to the inherited method, as in super.attach(owner).

Implementation

@override
void attach(SemanticsOwner owner) {
  super.attach(owner);
  while (owner._nodes.containsKey(id)) {
    // Ids may repeat if the Flutter has generated > 2^16 ids. We need to keep
    // regenerating the id until we found an id that is not used.
    _id = _generateNewId();
  }
  owner._nodes[id] = this;
  owner._detachedNodes.remove(this);
  if (_dirty) {
    _dirty = false;
    _markDirty();
  }
  if (_children != null) {
    for (final SemanticsNode child in _children!) {
      child.attach(owner);
    }
  }
}