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 |1 Answer
Reset to default 1The 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.
onTapDown
seems promising as theTapDownDetails
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