Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Container onPressed?

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?

like image 956
OhMad Avatar asked Apr 29 '17 07:04

OhMad


People also ask

Can we make a container clickable in flutter?

You can make widgets like Container, Card, Text, or any widget clickable in Flutter with the help of InkWell and GestureDetector widgets.

What is difference between onTap and onPressed flutter?

onPressed is usually on buttons while onTap is For any other widget you add behavior to with smtin lyk InkWell or GestureDetector.


1 Answers

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"),               ]           ),         )     ); 
like image 112
guest3523 Avatar answered Sep 21 '22 13:09

guest3523