具有硬编码滑动手势时,点击被视为垂直拖动

Tap is perceived as vertical drag when having hardcoded swipe gesture

我有 1 个手势检测器,可以包裹 10 张不同的卡片,并且可以滑动它们。每张卡都有 3 个点按手势检测器(基本上是按钮)。滑动按预期工作,但前 6 张卡片在点击时不会触发点击动作(Gesture Arena 告诉我水平拖动正在对抗垂直拖动 -> 因此点击手势被视为垂直拖动)。

我觉得奇怪的是最后 4 张卡片在点击和滑动时触发非常完美

我试过将 GestureDetectors 更改为 InkWell,但没有成功。

@override
  Widget build(BuildContext context) {
    return GestureDetector(
      onHorizontalDragStart: _onHorizontalDragStart,
      onHorizontalDragUpdate: _onHorizontalDragUpdate,
      onHorizontalDragEnd: _onHorizontalDragEnd,
      behavior: HitTestBehavior.translucent,
      child: Stack(
      children: _buildCards(),
    ),
    );
  }

List<Widget> _buildCards() {
        return [
          _buildCard(0, 10, scrollPercent),
          _buildCard(1, 10, scrollPercent),
          _buildCard(2, 10, scrollPercent),
          _buildCard(3, 10, scrollPercent),
          _buildCard(4, 10, scrollPercent),
          _buildCard(5, 10, scrollPercent),
          _buildCard(6, 10, scrollPercent),
          _buildCard(7, 10, scrollPercent),
          _buildCard(8, 10, scrollPercent),
          _buildCard(9, 10, scrollPercent),
        ];
      }

Widget _buildCard(int cardIndex, int cardCount, double scrollPercent) {
    final cardScrollPercent = scrollPercent / (1 / cardCount);
    final parallax = scrollPercent - (cardIndex / cardCount);

    return FractionalTranslation(
      translation: Offset(cardIndex - cardScrollPercent, 0.0),
      child: Transform(
        transform: _buildCardProjection(cardScrollPercent - cardIndex),
              child: card1(parallax, cardIndex
        ),
      )
      );
  }

Card1 最后上诉,它代表卡本身.. 这是 Card1

的 GestureDetector 的 onTap属性 的代码
onTap: () {
 showDialog(
    context: context,
    builder: (BuildContext context) => CustomDialog(
       title: "Title",
       description:"Test",
       buttonText: "Okay",
  ),

); },

听起来您可能有兴趣用 PageView 小部件替换您的设置。它使用 PageController 来管理滑动手势。查看上面的视频 Widget of the Week - PageView