Solved: How can I implement OnPressed callback for Text widget, Flutter

Question

Asked by Fathima k on March 02, 2018 (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

Question answered by Rémi R (source).

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"),
);
DART FLUTTER TEXT WIDGET
SHARE: