scrollToGlobalKey method

Future<bool> scrollToGlobalKey({
  1. required GlobalKey<State<StatefulWidget>> globalKey,
  2. double alignment = 0.0,
  3. Duration duration = Durations.short4,
  4. Curve curve = Curves.easeOut,
  5. ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit,
})

Implementation

Future<bool> scrollToGlobalKey({
  required GlobalKey globalKey,
  double alignment = 0.0,
  Duration duration = Durations.short4,
  Curve curve = Curves.easeOut,
  ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit,
}) async {
  final BuildContext? context = globalKey.currentContext;
  if (context == null) {
    return false;
  }
  await Scrollable.ensureVisible(
    context,
    alignment: alignment,
    duration: duration,
    curve: curve,
    alignmentPolicy: alignmentPolicy,
  );
  return true;
}