ensureVisible method

Future<void> ensureVisible (RenderObject object, { double alignment: 0.0, Duration duration: Duration.zero, Curve curve: Curves.ease })

Animates the position such that the given object is as visible as possible by just scrolling this position.

Implementation

Future<void> ensureVisible(
  RenderObject object, {
  double alignment = 0.0,
  Duration duration = Duration.zero,
  Curve curve = Curves.ease,
}) {
  assert(object.attached);
  final RenderAbstractViewport viewport = RenderAbstractViewport.of(object);
  assert(viewport != null);

  final double target = viewport.getOffsetToReveal(object, alignment).offset.clamp(minScrollExtent, maxScrollExtent);

  if (target == pixels)
    return Future<void>.value();

  if (duration == Duration.zero) {
    jumpTo(target);
    return Future<void>.value();
  }

  return animateTo(target, duration: duration, curve: curve);
}