Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter iOS: taps on the status bar can't scroll to top

Tags:

flutter

CustomScrollView used in home page layout If you want to pull up and load more, you must define a ScrollController and pass it to CustomScrollView.

My code

ScrollController _scrollController = new ScrollController();
  @override
  void initState() {
    super.initState();
    _scrollController.addListener(() {
      if (_scrollController.position.pixels >=
          _scrollController.position.maxScrollExtent) {
        _loadMoreData();
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
    _scrollController.dispose();
  }
new CustomScrollView(
  controller: _scrollController,
  slivers: <Widget>[....],
)

However, if this is done, when there is a lot of data loaded, tap the status bar at the top will not scroll to the top! If you remove the controller in CustomScrollView, or change to PrimaryScrollController.of(context)

new CustomScrollView(
  controller: PrimaryScrollController.of(context),
)

this is OK! why ???

like image 596
sunmoon Avatar asked Nov 06 '22 23:11

sunmoon


1 Answers

Because Flutter engine tries to imitate the OS behaviour as closely as possible. This tap gesture is known as "return-to-top" on iOS and doesn't exist on Android at all. Furthermore, to stay as close to the iOS app behaviour as possible, this gesture only triggers the scrolling animation for PrimaryScrollController classes.

As a reference, in iOS native app development the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to true (source).

like image 52
nstosic Avatar answered Nov 15 '22 06:11

nstosic