我有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",
),
); }
答案 0 :(得分:0)
听起来您可能有兴趣用PageView小部件替换您的设置。它使用PageController来管理滑动手势。观看其中的视频Widget of the Week - PageView