Flutter ListView难以滚动,因为有手势的孩子的onTap属性

问题描述 投票:0回答:1

我在ListView中将GesturedDetector + Container用作子级,并且工作正常。但有时如果滚动时触摸“儿童”,则很难滚动。

因为GestureDetector将我的滚动检测为轻按,所以整个ListView不会滚动。如果我将onTap更改为onLongPress,则解决了,但不是我想要的。

所以,我的情况有什么好的解决方法吗?

现在我只有一个想法,可以使孩子们的余地更大,减少了碰到孩子的机会。

flutter flutter-layout
1个回答
0
投票

我已经尝试了以下代码来尝试重现您的问题,但是不会发生。当我拖动ListView上下移动时,当我点击它时会打印String。在您的应用程序上尝试使用此代码,看看问题是否还会发生。

ListView(
  children: List.generate(50, (index) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent, // You can try adding this to help
      onTap: () => print('item $index'),
      child: Container(
        alignment: Alignment.center,
        child: Text('item $index'),
        height: 40,
      ),
    );
  }),
)
© www.soinside.com 2019 - 2024. All rights reserved.