showInViewport static method
Rect?
showInViewport({
- RenderObject? descendant,
- Rect? rect,
- required RenderLayoutBox viewport,
- Duration duration = Duration.zero,
- Curve curve = Curves.ease,
- AxisDirection? axisDirection,
Implementation
static Rect? showInViewport({
RenderObject? descendant,
Rect? rect,
required RenderLayoutBox viewport,
Duration duration = Duration.zero,
Curve curve = Curves.ease,
AxisDirection? axisDirection,
}) {
if (descendant == null) {
return rect;
}
Rect? showVertical(Rect? rect) {
return _showInViewportForAxisDirection(
descendant: descendant,
viewport: viewport,
axis: Axis.vertical,
rect: rect,
duration: duration,
curve: curve,
);
}
Rect? showHorizontal(Rect? rect) {
return _showInViewportForAxisDirection(
descendant: descendant,
viewport: viewport,
axis: Axis.horizontal,
rect: rect,
duration: duration,
curve: curve,
);
}
switch (axisDirection) {
case AxisDirection.left:
case AxisDirection.right:
return showHorizontal(rect);
case AxisDirection.up:
case AxisDirection.down:
return showVertical(rect);
case null:
// Update rect after revealing in one axis before revealing in the next.
rect = showHorizontal(rect) ?? rect;
// We only return the final rect after both have been revealed.
rect = showVertical(rect);
if (rect == null) {
// `descendant` is between leading and trailing edge and hence already
// fully shown on screen.
assert(viewport.parent != null);
final Matrix4 transform = descendant.getTransformTo(viewport.parent);
return MatrixUtils.transformRect(
transform,
rect ?? _obtainSafePaintBounds(descendant),
);
}
return rect;
}
}