scrollToTop function

void scrollToTop({
  1. bool smooth = true,
  2. int y = 0,
  3. bool fixSafariIOS = false,
  4. int? delayMs,
})

Scrolls viewport to the top.

  • If fixSafariIOS is true it will detect Safari on iOS (isSafariIOS) and will use y as 1 (not 0) to avoid a bug with direct scroll to 0, where smooth is ignored and the viewport position is vertically shifted even at scrollX == 0. Bug still present on iOS 16.4 (latest version on current date).
  • See scrollTo.

Implementation

void scrollToTop(
    {bool smooth = true, int y = 0, bool fixSafariIOS = false, int? delayMs}) {
  if (fixSafariIOS && y == 0 && isSafariIOS()) {
    y = 1;
  }

  scrollTo(window.scrollX, y, smooth: smooth, delayMs: delayMs);
}