我知道onLongPress
会在一段时间后触发(比如500毫秒左右)。但是我想做的是当用户按下按钮3秒时触发一些动作。实际上我想设置onLongPress
的持续时间。
ElevatedButton(
onPressed: () => print('ok I\'m just fine'),
onLongPress: () => print('Trigger me when user presses me for like 3 seconds'),
style: ElevatedButton.styleFrom(
primary: Colors.red,
elevation: 4,
),
4条答案
按热度按时间bgtovc5b1#
我是怎么做到的:
wnvonmuf2#
您可以通过这种方式解决问题,使用带有计时器的GestureDetector的onPanCancel和onPanDown。
让我知道它是否适合你。
gstyhher3#
我今天做了一个包,你可以设置手势检测器的持续时间。如果你想,你可以试试https://pub.dev/packages/custom_long_tap
hjzp0vay4#