Text 如何为文本小部件flatter实现OnPressed回调

Text 如何为文本小部件flatter实现OnPressed回调,text,widget,dart,flutter,Text,Widget,Dart,Flutter,我有一个文本小部件,按下该小部件时必须显示另一条路线。但是对于文本小部件,我看不到任何onPressed()方法。请提供帮助。只需将标题包装在手势检测器中即可处理点击。然后调用Navigator的pushNamed重定向到新路线 new GestureDetector( onTap: () { Navigator.pushNamed(context, "myRoute"); }, child: new Text("my Title"), ); 使用 这也给了你很好的连锁反应

我有一个
文本小部件
,按下该小部件时必须显示另一条
路线
。但是对于
文本小部件
,我看不到任何onPressed()方法。请提供帮助。

只需将标题包装在
手势检测器中即可处理点击。然后调用
Navigator
pushNamed
重定向到新路线

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

这也给了你很好的连锁反应

 new InkWell(
          onTap: () {
            Navigator.pushNamed(context, "YourRoute");
          },
          child: new Padding(
            padding: new EdgeInsets.all(10.0),
            child: new Text("Tap Here"),
          ),
        );


对于颤振的所有小部件,您可以使用这些小部件实现onPressed

1。InkWell():使用此小部件,您可以在单击时添加连锁反应

InkWell(
     onTap: () {
         Navigator.pushNamed(context, "write your route");
     },
     child: new Text("Click Here"),
 );

2。GestureDetector():使用此小部件,您可以实现onTap、onDoubleTap、onLongPress等多种功能

GestureDetector(
     onTap: () {
         Navigator.pushNamed(context, "write your route");
     },
     onLongPress: (){
        // open dialog OR navigate OR do what you want
     }
     child: new Text("Save"),
 );
你可以用。因为它有一个透明的背景,所以看起来像一个文本小部件

            TextButton(
              onPressed: () {
                //action
              },
              child: Text(
                'Title Text', //title
                textAlign: TextAlign.end, //aligment
              ),
            ),

我上星期开始学弗利特。这是我所经历过的最令人惊奇的开发者体验。太好了。那么你把答案结合起来写自己的了?我喜欢这样不,我改进了上述答案,并编写了自己的@iDecodePoint来解释。
            TextButton(
              onPressed: () {
                //action
              },
              child: Text(
                'Title Text', //title
                textAlign: TextAlign.end, //aligment
              ),
            ),