I just have a simple Card like new Card(child: new Text('My cool card'))
and I want to be able to click anywhere on it to run some function, except there's no onPressed
method for a Card. I could add a button to the bottom, but that's not ideal for this situation.
Anyone know how to make the whole card clickable?
itemCount: _addCard, In the ItemBuilder we will pass the context , and the index and will return the Card . floatingActionButton:FloatingActionButton(onPressed: _incrementCard ;), So when you will tap the floating button it will generate one card for you in ListView.
A Card is a sheet of Material used to represent some related information, for example, an album, a geographical location, a meal, contact details, etc. containers: If you are familiar with HTML, think of containers like divs.
Flutter use composition over properties. Wrap the desired widget into a clickable one to achieve what you need.
Some clickable widgets : GestureDetector
, InkWell
, InkResponse
.
GestureDetector( onTap: () => ......, child: Card(...), );
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