scrollToObject function
dynamic
scrollToObject(
- RenderObject object,
- ScrollController scrollController,
- Duration duration,
- Curve curve,
- double overscroll,
Scroll to the given object
, which must be inside scrollController
s 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,
);
}
}