scrollToObject function

dynamic scrollToObject(
  1. RenderObject object,
  2. ScrollController scrollController,
  3. Duration duration,
  4. Curve curve,
  5. double overscroll,
)

Scroll to the given object, which must be inside scrollControllers viewport.

Implementation

scrollToObject(RenderObject object, ScrollController scrollController,
    Duration duration, Curve curve, double overscroll) {
  // Calculate the offset needed to show the object in the [ScrollView]
  // so that its bottom touches the top of the keyboard.
  final viewport = RenderAbstractViewport.of(object)!;
  final offset = viewport.getOffsetToReveal(object, 1.0).offset + overscroll;

  // If the object is covered by the keyboard, scroll to reveal it,
  // and add [focusPadding] between it and top of the keyboard.
  if (offset > scrollController.position.pixels) {
    scrollController.position.moveTo(
      offset,
      duration: duration,
      curve: curve,
    );
  }
}