ensureVisible method

Future<void> ensureVisible (
  1. BuildContext context,
  2. {double alignment: 0.0,
  3. Duration duration: Duration.zero,
  4. Curve curve: Curves.ease,
  5. ScrollPositionAlignmentPolicy alignmentPolicy: ScrollPositionAlignmentPolicy.explicit}
)

Scrolls the scrollables that enclose the given context so as to make the given context visible.

Implementation

static Future<void> ensureVisible(
  BuildContext context, {
  double alignment = 0.0,
  Duration duration = Duration.zero,
  Curve curve = Curves.ease,
  ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit,
}) {
  final List<Future<void>> futures = <Future<void>>[];

  ScrollableState scrollable = Scrollable.of(context);
  while (scrollable != null) {
    futures.add(scrollable.position.ensureVisible(
      context.findRenderObject(),
      alignment: alignment,
      duration: duration,
      curve: curve,
      alignmentPolicy: alignmentPolicy,
    ));
    context = scrollable.context;
    scrollable = Scrollable.of(context);
  }

  if (futures.isEmpty || duration == Duration.zero)
    return Future<void>.value();
  if (futures.length == 1)
    return futures.single;
  return Future.wait<void>(futures).then<void>((List<void> _) => null);
}