实际上,我目前正在使用 Division 来处理按钮的手势。但我仍然在寻找一种方法来完成它,无论有没有 split 。我希望在 1000 毫秒而不是 500 毫秒后启动按钮的长按。
我已经在 SO 和其他网站上进行了搜索,但似乎仍然找不到这个确切问题的解决方案。
这就是 Division 的运作方式。我试过使用 while 和 Future.delayed 但似乎无法使其正常工作。但是如果它不在 Division 的 Gesture() 中就完全没问题。因为我只想让它正常工作,不管它是否使用分区。
Gestures()
..isTap((isTapped) => setState(() => pressed = isTapped))
..onLongPress(() { print("long pressed"); })
提前谢谢你。
最佳答案
您可以使用 dart:async
Timer
来做到这一点
class _MyWidgetState extends State<MyWidget> {
Timer timer;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: (_) {
timer = Timer(Duration(milliseconds: 1000), onLongerPress);
},
onTapUp: (_){
timer.cancel();
},
child: Container(child: Center(child: Text('Click here')), width: 200, height: 50, color: Colors.green),
);
}
void onLongerPress() {
print('onLongerPress called');
}
}
关于android - 检查在 Flutter 中按下按钮多长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63445281/