detach method
void
detach()
Called when the render object is detached from the render tree.
Subclasses can override to release resources or unregister handlers.
Implementation
void detach() {
final formerOwner = _pipelineOwner;
final attachment = _inspectSubtree(this, formerOwner);
if (attachment.state == _SubtreeState.detached) {
return;
}
if (formerOwner == null) {
throw StateError('Attached subtree has no root PipelineOwner.');
}
final childSnapshot = <RenderObject>[];
visitChildren(childSnapshot.add);
formerOwner._forget(this);
_pipelineOwner = null;
for (final child in childSnapshot) {
if (identical(child._pipelineOwner, formerOwner)) {
child.detach();
} else if (child._pipelineOwner != null) {
throw StateError(
'Render subtree changed owner while it was being detached.',
);
}
}
}