简体   繁体   English

颤动:检测多个小部件上的点击

[英]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). 我有一个4行按钮,如果我想调用不同的回调(或具有不同参数的相同功能),点击每个按钮和每个按钮组合(同时按下两个或更多按钮)。

I have no clue. 我没有任何线索。

  1. First you'll need to wrap each button with a GestureDetector , read more about these here 首先,您需要使用GestureDetector包装每个按钮, 在这里阅读更多相关信息
  2. You need a method,(_handleMultiTouch) to handle all the onTapDown , onTapUp and onTapCancel events. 您需要一个方法(_ handleMultiTouch)来处理所有onTapDownonTapUponTapCancel事件。

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

  3. In _handleMultiTouch(int id, var event) is where you'll declare all the logic for handling multi touch. _handleMultiTouch(int id, var event)中,您将声明处理多点触摸的所有逻辑。 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. 如果用户点击了一个或两个按钮,或者用户停止点击按钮1等,您将保存。使用开关或if语句并保存触摸状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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