I am very confused about how RenderObjects
are managed in Flutter. A RenderObject
is created by its Element
, But when exactly is the render object detached
? What are the use cases for this?
here in below, i try to remove listener but its seem i also need to remove it at detach
?
(context: I am trying to monopolize the focus event on this render object (its always return handled
– this RenderObject is act like custom-text-laTex-table editor).
@override
void attach(PipelineOwner owner) {
super.attach(owner);
FocusManager.instance.addEarlyKeyEventHandler(_documentController.keyboardHanlder);
}
@override
void detach() {
FocusManager.instance.removeEarlyKeyEventHandler(_documentController.keyboardHanlder);
super.detach();
}
@override
void dispose() {
FocusManager.instance.removeEarlyKeyEventHandler(_documentController.keyboardHanlder);
super.dispose();
}
From the documentation, we know:
“Mark this render object as detached from its PipelineOwner.
Typically called only from the parent’s detach, and by the owner to
mark the root of a tree as detached.Subclasses with children should override this method to detach all
their children after calling the inherited method, as in
super.detach().”
However, it’s still not clear to me why a render object would be detached
but not disposed
.
- What are the specific scenarios where a render object is detached but not yet disposed?
- So if its true, its mean we can create an element and create a render object, then attach it to another render object?
I appreciate any clarification or examples that can help me understand this better. Thank you.