How can I implement OnPressed callback for Text widget, Flutter
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"), )
For All the widget of Flutter you can implement onPressed using these widget
1. InkWell() : Using this widget you can add ripple effect on clicking
InkWell( onTap: () { Navigator.pushNamed(context, "write your route"); }, child: new Text("Click Here"), );
2. GestureDetector() : Using this widget you can implement, onTap, onDoubleTap, onLongPress and many more
GestureDetector( onTap: () { Navigator.pushNamed(context, "write your route"); }, onLongPress: (){ // open dialog OR navigate OR do what you want } child: new Text("Save"), );