在Flutter中,子控件如何阻止其可滚动父控件的滚动? [英] In Flutter, how can a child widget prevent the scrolling of its scrollable parent?

查看:234
本文介绍了在Flutter中,子控件如何阻止其可滚动父控件的滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可滚动的小部件,例如ListView,其中包含一些特殊的小部件.

I have a scrollable widget, say a ListView, which contains some special widget.

当用户尝试通过在该小部件顶部滚动来尝试滚动时,如何防止滚动条滚动?

How can I prevent the scrollable to scroll when the user tries to scroll by starting to scroll on top of that widget?

换句话说,我希望该小部件像一个小孔",以防止可滚动屏幕感应到那里的手势.

In other words, I want that widget to be like a "hole" that prevents the scrollable to sense gestures there.

推荐答案

GestureDetector包裹小部件,并在其中实现空手势功能.

Wrap the widget with GestureDetector and implement empty gesture functions in it.

GestureDetector(
   onVerticalDragUpdate: (_) {},
   child: YourWidget
),

这篇关于在Flutter中,子控件如何阻止其可滚动父控件的滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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