简体   繁体   中英

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.

  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 , onTapUp and 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM