animateToTop method
Implementation
Future<void> animateToTop() async {
await Future<void>.delayed(const Duration(milliseconds: 200));
while (shouldAnimateToTop) {
// The overlay (and its scroll view) can be torn down while this loop is
// suspended on the delay or an animateTo step; reading offset/position
// with no attached position then throws — 'Bad state: No element' in a
// release build (#686), a '_positions.isNotEmpty' assert in debug. Bail
// out like the scroll listener does.
if (!scrollController.hasClients) return;
shouldAnimateToTop = scrollController.offset > 0;
await scrollController.animateTo(
max(scrollController.offset - 30, 0),
duration: const Duration(milliseconds: 20),
curve: Curves.easeInOutCubic,
);
}
}