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.


Future<void> ensureVisible(
  RenderObject object, {
  double alignment = 0.0,
  Duration duration = Duration.zero,
  Curve curve = Curves.ease,
}) {
  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) {
    return Future<void>.value();

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