Cant added flutter onPress

As far as I can see, you are missing a widget which has a onPressed or onTap property, none of your widgets is configured to be press-able. Easiest way to achieve this, is making use of the GestureDetector widget, which can listen to various kinds of gestures, including onTap. Just Wrap it around the part of your widget tree which should be press-able – syntax for this use case goes like:

GestureDetector(
  /// This makes sure the whole area is clickable and not only the actual widgets inside
  behavior: HitTestBehavior.translucent,
  /// Your press function
  onTap: press,
  /// The rest of your widget tree
  child: ...
)

There are quite some widgets which have interaction properties like onPressed on their own, like FlatButton or ListTile. I would recommend to take a look at the Flutter widget catalog where you can see different kind of existing widgets which solve common problems like touch events, input etc.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top