showInViewport static method
- RenderObject? descendant,
- Rect? rect,
- required RenderTwoDimensionalViewport viewport,
- Duration duration = Duration.zero,
- Curve curve = Curves.ease,
- AxisDirection? axisDirection,
Make (a portion of) the given descendant
of the given viewport
fully
visible in one or both dimensions of the viewport
by manipulating the
ViewportOffsets.
The axisDirection
determines from which axes the descendant
will be
revealed. When the axisDirection
is null, both axes will be updated to
reveal the descendant.
The optional rect
parameter describes which area of the descendant
should be shown in the viewport. If rect
is null, the entire
descendant
will be revealed. The rect
parameter is interpreted
relative to the coordinate system of descendant
.
The returned Rect describes the new location of descendant
or rect
in the viewport after it has been revealed. See RevealedOffset.rect
for a full definition of this Rect.
The parameter viewport
is required and cannot be null. If descendant
is null, this is a no-op and rect
is returned.
If both descendant
and rect
are null, null is returned because there
is nothing to be shown in the viewport.
The duration
parameter can be set to a non-zero value to animate the
target object into the viewport with an animation defined by curve
.
See also:
- RenderObject.showOnScreen, overridden by RenderTwoDimensionalViewport to delegate to this method.
Implementation
static Rect? showInViewport({
RenderObject? descendant,
Rect? rect,
required RenderTwoDimensionalViewport viewport,
Duration duration = Duration.zero,
Curve curve = Curves.ease,
AxisDirection? axisDirection,
}) {
if (descendant == null) {
return rect;
}
Rect? showVertical(Rect? rect) {
return RenderTwoDimensionalViewport._showInViewportForAxisDirection(
descendant: descendant,
viewport: viewport,
axis: Axis.vertical,
rect: rect,
duration: duration,
curve: curve,
);
}
Rect? showHorizontal(Rect? rect) {
return RenderTwoDimensionalViewport._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 ?? descendant.paintBounds,
);
}
return rect;
}
}