How can I implement OnPressed callback for Text widget, Flutter

前端 未结 3 1568
北海茫月
北海茫月 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:49

    Use InkWell

    this gives you nice ripple effect as well

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

    or

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

提交回复
热议问题