// 防止二次点击
  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
              ),
            )

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐