How can I implement OnPressed callback for Text widget, Flutter

Fathima km picture Fathima km · Mar 2, 2018 · Viewed 33.5k times · Source

I have a Text widget on pressing which another Route has to be shown. But I could not see any onPressed() method for the Text widget. Please Help.

Answer

Rémi Rousselet picture Rémi Rousselet · Mar 2, 2018

Just wrap your title in a GestureDetector to handle clicks. Then call Navigator's pushNamed to redirect to a new route.

new GestureDetector(
  onTap: () {
    Navigator.pushNamed(context, "myRoute");
  },
  child: new Text("my Title"),
);