I have this container:
new Container( width: 500.0, padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0), color: Colors.green, child: new Column( children: [ new Text("Ableitungen"), ] ), ),
When the user clicks on the Container
, I want an onPressed()
method to be fired (like it can be done with IconButton
for example). How can I achieve this behaviour with Container
?
You can make widgets like Container, Card, Text, or any widget clickable in Flutter with the help of InkWell and GestureDetector widgets.
onPressed is usually on buttons while onTap is For any other widget you add behavior to with smtin lyk InkWell or GestureDetector.
I guess you can use GestureDetector
widget like this:
new GestureDetector( onTap: (){ print("Container clicked"); }, child: new Container( width: 500.0, padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0), color: Colors.green, child: new Column( children: [ new Text("Ableitungen"), ] ), ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With