如何确定滚动条在颤动中是否可见/附加?
我想在滚动条可见时为其添加空间/填充。
如何确定滚动条在 flutter 小部件中是否可见?
I want to add space/padding for a scrollbar when it is visible.
How can I find out, if a scrollbar is visible in a flutter widget?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过以下内容,我可以找出是否有滚动条
,当 hasScrollbar 为 true 时,我为其添加填充:
Through the following I could find out if there is a scrollbar
and when hasScrollbar is true I add padding for it:
这个库可以帮助你做到这一点
https://pub.dev/packages/visibility_detector
this lib can help you to do it
https://pub.dev/packages/visibility_detector
老问题,但从 2025 年开始,您可以使用包 assorted_layout_widgets 中的小部件
DetectScroll
。DetectScroll
可以检测滚动条是否可见,并告诉您滚动条的宽度。这对于相对于滚动条定位小部件非常有用,这样滚动条就不会与它们重叠。当滚动条永久可见时(通常在 Web 和桌面上),这一点可能很重要。直接用 DetectScroll 包裹您关心的滚动条:
然后,在后代小部件中,您可以获得当前滚动状态和滚动条宽度:
例如,假设您想向可滚动的右上角,并且仅在可见时才考虑滚动条宽度:
注意我是包作者。
Old question, but as of 2025 you can use widget
DetectScroll
from package assorted_layout_widgets.DetectScroll
can detect if a scrollbar is likely visible, and also tell you the width of the scrollbar. This is useful for positioning widgets relative to the scrollbar, so that the scrollbar doesn't overlap them. This can be important when the scrollbar is permanently visible, usually on the Web and desktop.Wrap the scrollable you care about directly with a
DetectScroll
:Then, in a descendent widget, you can get the current scroll state and the scrollbar width:
For example, suppose you want to add a help button to the top-right corner of a scrollable, and account for the scrollbar width only if it's visible:
Note I'm the package author.