showInViewport static method
- RenderObject? descendant,
- Rect? rect,
- required RenderAbstractViewport viewport,
- required ViewportOffset offset,
- Duration duration = Duration.zero,
- Curve curve = Curves.ease,
Make (a portion of) the given descendant of the given viewport fully
visible in the viewport by manipulating the provided ViewportOffset
offset.
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.
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 RenderViewportBase and the renderer for SingleChildScrollView to delegate to this method.
Implementation
static Rect? showInViewport({
RenderObject? descendant,
Rect? rect,
required RenderAbstractViewport viewport,
required ViewportOffset offset,
Duration duration = Duration.zero,
Curve curve = Curves.ease,
}) {
if (descendant == null) {
return rect;
}
final RevealedOffset leadingEdgeOffset = viewport.getOffsetToReveal(
descendant,
0.0,
rect: rect,
);
final RevealedOffset trailingEdgeOffset = viewport.getOffsetToReveal(
descendant,
1.0,
rect: rect,
);
final double currentOffset = offset.pixels;
final RevealedOffset? targetOffset = RevealedOffset.clampOffset(
leadingEdgeOffset: leadingEdgeOffset,
trailingEdgeOffset: trailingEdgeOffset,
currentOffset: currentOffset,
);
if (targetOffset == null) {
// `descendant` is between leading and trailing edge and hence already
// fully shown on screen. No action necessary.
assert(viewport.parent != null);
final Matrix4 transform = descendant.getTransformTo(viewport.parent);
return MatrixUtils.transformRect(transform, rect ?? descendant.paintBounds);
}
offset.moveTo(targetOffset.offset, duration: duration, curve: curve);
return targetOffset.rect;
}