applyParentData method
- RenderObject renderObject
Write the data from this widget into the given render object's parent data.
The framework calls this function whenever it detects that the RenderObject associated with the child has outdated RenderObject.parentData. For example, if the render object was recently inserted into the render tree, the render object's parent data might not match the data in this widget.
Subclasses are expected to override this function to copy data from their
fields into the RenderObject.parentData field of the given render
object. The render object's parent is guaranteed to have been created by a
widget of type T
, which usually means that this function can assume that
the render object's parent data object inherits from a particular class.
If this function modifies data that can change the parent's layout or painting, this function is responsible for calling RenderObject.markNeedsLayout or RenderObject.markNeedsPaint on the parent, as appropriate.
Implementation
@override
void applyParentData(RenderObject renderObject) {
assert(renderObject.parentData is KeepAliveParentDataMixin);
final KeepAliveParentDataMixin parentData = renderObject.parentData! as KeepAliveParentDataMixin;
if (parentData.keepAlive != keepAlive) {
// No need to redo layout if it became true.
parentData.keepAlive = keepAlive;
final RenderObject? targetParent = renderObject.parent;
if (targetParent is RenderObject && !keepAlive) {
targetParent.markNeedsLayout();
}
}
}