handleStatusBarTap method
override
Called when the user taps the status bar on iOS, to scroll a scroll view to the top.
This event should usually only be handled by at most one scroll view, so implementer(s) of this callback must coordinate to determine the most suitable scroll view for handling this event.
This callback is only called on iOS. The default implementation provided by WidgetsBindingObserver does nothing.
See also:
- Scaffold and CupertinoPageScaffold which use this callback to implement iOS scroll-to-top.
Implementation
@override
void handleStatusBarTap() {
super.handleStatusBarTap();
assert(widget.primary);
final ScrollController? primaryScrollController = PrimaryScrollController.maybeOf(context);
if (primaryScrollController != null &&
primaryScrollController.hasClients &&
// TODO(LongCatIsLooong): the iOS embedder used to send status bar tap
// evets as fake touches at Offset.zero, such that at most one Scaffold
// (usually the foreground primary Scaffold) can handle the status bar
// tap event, thanks to hit-testing and gesture disambiguation.
// To keep that behavior, this widget performs an additional hit-test here
// to make sure the status bar tap is only handled if the scaffold is
// hit-testable (thus in the foreground)
// Switch to a better solution when available:
// https://github.com/flutter/flutter/issues/182403
_HitTestableAtOrigin.hitTestableAtOrigin(_statusBarKey)) {
primaryScrollController.animateTo(
0.0,
duration: const Duration(milliseconds: 1000),
curve: Curves.easeOutCirc,
);
}
}