// 防止二次点击
static DateTime _lastTime;
preventDoubleTap({int interval}){
DateTime _nowTime = DateTime.now();
if(_lastTime == null || _nowTime.difference(_lastTime) > Duration(milliseconds: interval??600)){
_lastTime = _nowTime;
return true;
}else {
_lastTime = _nowTime;
return false;
}
}
调用:GestureDetector(
onTap: () {
if(!preventDoubleTap(interval:1000)){
toast('请勿重复点击');
return;
}
},
child: Container(
width:100, height:50
),
)
flutter防止按钮重复点击
于 2023-04-06 10:16:47 首次发布
该代码示例展示了一个防止短时间内重复点击的功能。通过`preventDoubleTap`函数,设置指定间隔时间内(默认600毫秒)只允许一次点击,如果在规定时间内再次点击,将返回错误提示。此功能常用于用户界面以避免误操作。
4774

被折叠的 条评论
为什么被折叠?



