toScrollKey static method

Future<void> toScrollKey(
  1. GlobalKey<State<StatefulWidget>> key, {
  2. double alignment = 0.5,
  3. Duration duration = Durations.long4,
})

Implementation

static Future<void> toScrollKey(
  GlobalKey key, {
  double alignment = 0.5,
  Duration duration = Durations.long4,
}) async {
  final context = key.currentContext;
  if (context == null) return;

  final renderObject = context.findRenderObject();
  if (renderObject == null) return;

  final scrollable = Scrollable.maybeOf(context);
  if (scrollable == null) return;

  await Future.delayed(duration);

  await scrollable.position.ensureVisible(
    renderObject,
    duration: Durations.medium1,
    curve: Curves.easeInOut,
    alignment: alignment,
  );
}