How can I implement OnPressed callback for Text widget, Flutter

前端 未结 3 1567
北海茫月
北海茫月 2021-02-05 00:22

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. Plea

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 00:36

    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"),
    );
    

提交回复
热议问题