最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Is there a way in Flutter to detect which part of a Widget was pressed? - Stack Overflow

programmeradmin3浏览0评论

Is there a way in Flutter to detect which side of a button is pressed? For example, in the attached image, is it possible to tell when the '5' button is pressed whether the user pressed their finger on the 'A', 'B', 'C' or 'D' part or a combination of these?

Is there a way in Flutter to detect which side of a button is pressed? For example, in the attached image, is it possible to tell when the '5' button is pressed whether the user pressed their finger on the 'A', 'B', 'C' or 'D' part or a combination of these?

Share Improve this question asked Mar 30 at 18:01 danieldaniel 235 bronze badges 4
  • You'll want to have a look at api.flutter.dev/flutter/widgets/GestureDetector-class.html – Frank van Puffelen Commented Mar 30 at 21:30
  • I already read that page and unfortunately I didn't saw any event that can accomplish what I described in the original post – daniel Commented Mar 30 at 21:43
  • onTapDown seems promising as the TapDownDetails has info about where the tap happened. If you tried to make a gesture detector work but got stuck, it's more likely we can help if you show what you tried. – Frank van Puffelen Commented Mar 30 at 21:53
  • I think this is it as I notice that it has a property called localPosition of type Offset. I'll try to see if it works, thanks! – daniel Commented Mar 31 at 17:37
Add a comment  | 

1 Answer 1

Reset to default 1

The idiomatic way to do this in Flutter is to break down the top-level widget into subwidgets, in your case one for each element in the screenshot. Then you can handle the onTap for each of these subwidgets.


If you want to handle this with a single widget, that is possible too though. To detect where on a widget the user taped, you can implement GestureDetector. Check out the examples in that documentation.

For this specific use-case, have a look at onTapDown as the TapDownDetails contains information about where exactly the tap happened.

发布评论

评论列表(0)

  1. 暂无评论