[英]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. 我没有任何线索。
GestureDetector
, read more about these here GestureDetector
包装每个按钮, 在这里阅读更多相关信息 You need a method,(_handleMultiTouch) to handle all the onTapDown
, onTapUp
and onTapCancel
events. 您需要一个方法(_ handleMultiTouch)来处理所有
onTapDown
, onTapUp
和onTapCancel
事件。
onTapDown => _handleMultiTouch(..somebuttonId, the event)
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.