debugVisitOnstageChildren method Null safety
- ElementVisitor visitor
override
Calls the argument for each child considered onstage.
Classes like Offstage and Overlay override this method to hide their children.
Being onstage affects the element's discoverability during testing when you use Flutter's Finder objects. For example, when you instruct the test framework to tap on a widget, by default the finder will look for onstage elements and ignore the offstage ones.
The default implementation defers to visitChildren and therefore treats the element as onstage.
See also:
- Offstage widget that hides its children.
- Finder that skips offstage widgets by default.
- RenderObject.visitChildrenForSemantics, in contrast to this method, designed specifically for excluding parts of the UI from the semantics tree.
Implementation
@override
void debugVisitOnstageChildren(ElementVisitor visitor) {
_childElements.values.cast<Element>().where((Element child) {
final SliverMultiBoxAdaptorParentData parentData = child.renderObject!.parentData! as SliverMultiBoxAdaptorParentData;
final double itemExtent;
switch (renderObject.constraints.axis) {
case Axis.horizontal:
itemExtent = child.renderObject!.paintBounds.width;
break;
case Axis.vertical:
itemExtent = child.renderObject!.paintBounds.height;
break;
}
return parentData.layoutOffset != null &&
parentData.layoutOffset! < renderObject.constraints.scrollOffset + renderObject.constraints.remainingPaintExtent &&
parentData.layoutOffset! + itemExtent > renderObject.constraints.scrollOffset;
}).forEach(visitor);
}