Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How do you make a card clickable?

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?

like image 375
Jus10 Avatar asked Apr 21 '18 19:04

Jus10


People also ask

How do you add dynamic cards in Flutter?

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.

What is the difference between card and container in Flutter?

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.


1 Answers

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(...), ); 
like image 96
Rémi Rousselet Avatar answered Sep 28 '22 23:09

Rémi Rousselet