Flutter ListView,SliverList等内部的当前滚动偏移量 [英] Current scroll offset inside a Flutter ListView, SliverList,etc

查看:916
本文介绍了Flutter ListView,SliverList等内部的当前滚动偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Flutter ListView,SliverList 等内部的当前滚动偏移量?

How do I get the current scroll offset inside a Flutter ListView, SliverList, etc?

推荐答案


  • 如果您在滚动视图中,请使用 Scrollable.of(context).position.pixels

  • 如果您在外面,您可能想将 ScrollController 作为滚动视图的控制器参数,那么您可以阅读 controller.offset

  • 或者,将滚动通知与 NotificationListener 一起使用。
  • li>

    • If you're inside the scroll view use Scrollable.of(context).position.pixels.
    • If you're outside, you probably want to hand a ScrollController in as the controller argument of the scroll view, then you can read controller.offset.
    • Alternatively, use scroll notifications with NotificationListener.
    • 这是在Flutter Gitter上询问的,并回答:
      https://gitter.im/flutter/flutter?at=591243f18a05641b1167be0e

      This was asked on Flutter Gitter, and answered: https://gitter.im/flutter/flutter?at=591243f18a05641b1167be0e

      这篇关于Flutter ListView,SliverList等内部的当前滚动偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆