DEV Community

Rui Kowase
Rui Kowase

Posted on

How to add a click event to any widget of Flutter

How to add a click event to any widget of Flutter.

TL;DR

Use GestureDetector widget

Sample code

GestureDetector(
  onTap: () {
    print("onTap called.");
  },
  child: Text("foo"),
),
Enter fullscreen mode Exit fullscreen mode

Environment

  • Flutter 0.1.5
  • Dart 2.0.0-dev.28.0

Link

user interface - Flutter - Container onPressed? - Stack Overflow
https://stackoverflow.com/questions/43692923/flutter-container-onpressed

Top comments (2)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
tayormi profile image
Temitope Ajiboye

Have you tried using InkWell()?