Flutter ListView、SliverList 等中的当前滚动偏移量 [英] Current scroll offset inside a Flutter ListView, SliverList,etc
本文介绍了Flutter ListView、SliverList 等中的当前滚动偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取 Flutter ListView
、GridView
、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 readcontroller.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屋!
查看全文