简体   繁体   English

Flutter iOS:点击状态栏无法滚动到顶部

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

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.主页布局中使用的CustomScrollView 如果想上拉加载更多,必须定义一个ScrollController 并传递给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)如果删除 CustomScrollView 中的控制器,或更改为 PrimaryScrollController.of(context)

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

this is OK!还行吧! why ???为什么 ???

Because Flutter engine tries to imitate the OS behaviour as closely as possible.因为 Flutter 引擎试图尽可能地模仿操作系统的行为。 This tap gesture is known as "return-to-top" on iOS and doesn't exist on Android at all.这种点击手势在 iOS 上被称为“返回顶部” ,在 Android 上根本不存在。 Furthermore, to stay as close to the iOS app behaviour as possible, this gesture only triggers the scrolling animation for PrimaryScrollController classes.此外,为了尽可能接近 iOS 应用程序的行为,此手势仅触发PrimaryScrollController类的滚动动画。

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 ).作为参考,在 iOS 本机应用程序开发中,如果屏幕上有多个滚动视图将 scrollsToTop 设置为 true ( source ),则滚动到顶部手势不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM