本文介绍了颤振检测三次轻击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我希望能够在Flutter小部件中检测到三次敲击(甚至更多次),尽管GestureDetector只能检测到内置的两次敲击.

I would like to be able to detect a triple tap (or even more) in a Flutter widget, although GestureDetector only has detection for double-tap built in.

对我而言,检测小部件上的三次轻击最简单的方法是什么?

What is the easiest way for me to detect a triple tap on a widget?

(我想不断单击屏幕的一部分以解锁一些开发人员选项)

(I want continually clicking on a part of the screen to unlock some developer options)

推荐答案

对此有点懒,实际上并不难

Was a bit lazy with this one, in reality it's not that hard

// init
int lastTap = DateTime.now().millisecondsSinceEpoch;
int consecutiveTaps = 0;

GestureDetector(
        onTap: () {
          int now = DateTime.now().millisecondsSinceEpoch;
          if (now - lastTap < 1000) {
            print("Consecutive tap");
            consecutiveTaps ++;
            print("taps = " + consecutiveTaps.toString());
            if (consecutiveTaps > 4){
              // Do something
            }
          } else {
            consecutiveTaps = 0;
          }
          lastTap = now;
        },
        child: ...
)

这篇关于颤振检测三次轻击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:53