How to create triple click button in flutter

前端 未结 2 955
小蘑菇
小蘑菇 2021-01-29 06:43

How can I implement a triple-click button in flutter?

On triple-click, the button will store an entry in Firebase database.

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 07:03

    Its pretty easy. You can use a GestureDetector() to check for the number of taps then you can provide your logic if there are 3 taps.

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

提交回复
热议问题