Search code examples
fluttergesture

Flutter: detecting tap on multiple widgets


I have a Row of 4 buttons, what if I want to call a different callback (or same function with different arguments) on tap on every individual button and on every combination of buttons (simultaneously pressing two or more buttons).

I have no clue.


Solution

    1. First you'll need to wrap each button with a GestureDetector, read more about these here
    2. You need a method,(_handleMultiTouch) to handle all the onTapDown,onTapUpand onTapCancel events.

      onTapDown => _handleMultiTouch(..somebuttonId, the event)

    3. In _handleMultiTouch(int id, var event) is where you'll declare all the logic for handling multi touch. Here you'll save if user has tapped one or two button, or the user stopped a tap on button 1, etc. Use a switch or a if statment and save the touch states.