// 防止二次点击
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 首次发布