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

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

问题描述

如何获取 Flutter ListViewGridView、SliverList` 等中的当前滚动偏移量?

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

推荐答案

  • 如果您在滚动视图中,请使用 Scrollable.of(context).position.pixels.
  • 如果你在外面,你可能想把 ScrollController 作为滚动视图的控制器参数,然后你可以阅读 controller.offset.李>
  • 或者,使用带有 NotificationListener 的滚动通知.
    • 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天全站免登陆