firstValidRenderObject method
Returns the first render object that complies with the following:
- Its parent data is
CellParentData
- Its parent is a
RenderSliverLayoutGrid
- If is an renderObject with less depth that the
renderObject
it can only have aRenderRepaintBoundary
orRenderIndexedSemantics
in between or aRenderRepaintBoundary
andRenderIndexedSemantics
in that order. These render objects could be added by the SliverLayoutGrid for accesibility and performance Notice this methid can return if it can't finde a render object that complies with these conditions
Implementation
RenderObject? firstValidRenderObject(RenderObject renderObject) {
RenderObject targetObject = renderObject;
bool isValidRenderObject(RenderObject renderObject) {
return renderObject.parent is RenderSliverLayoutGrid &&
renderObject.parentData is CellParentData;
}
// First check, true if there is no `RenderRepaintBoundary` and `RenderIndexedSemantics`
// and renderObject is valid
if (isValidRenderObject(targetObject)) {
return targetObject;
} else {
targetObject = renderObject.parent as RenderObject;
}
// Second check, true if there is a `RenderRepaintBoundary` and its
// parent is valid
if (targetObject is RenderRepaintBoundary &&
isValidRenderObject(targetObject)) {
return targetObject;
} else if (targetObject is! RenderIndexedSemantics) {
targetObject = targetObject.parent as RenderObject;
}
// Third check, true if there is a `RenderIndexedSemantics` and its
// parent is valid
// It can be nested [RenderRepaintBoundary/RenderIndexedSemantics/TargetRenderObject]
if (targetObject is RenderIndexedSemantics &&
isValidRenderObject(targetObject)) {
return targetObject;
}
return null;
}