首页 文章

如何为Text小部件Flutter实现OnPressed回调

提问于
浏览
0

我有一个 Text widget 在按下,另一个 Route 必须显示 . 但我看不到 Text widget 的任何onPressed()方法 . 请帮忙 .

2 回答

  • 1

    只需将您的 Headers 包装在 GestureDetector 中即可处理点击次数 . 然后调用 NavigatorpushNamed 重定向到新路由 .

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

    这也给你很好的涟漪效果

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

    要么

    new FlatButton(
              onPressed: () {
                Navigator.pushNamed(context, "YourRoute");
              },
              child: new Text("Tap Here"),
            )
    

相关问题