Flutter: How do you make a card clickable?

后端 未结 6 1349
迷失自我
迷失自我 2020-12-15 02:40

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 n

6条回答
  •  被撕碎了的回忆
    2020-12-15 03:05

    The most preferred way is to add ListTile as Card child. Not only does ListTile contain the method onTap it also helps you in making Card interesting.

    Card(
      child: ListTile(
        title: Text('Title')
        leading: CircleAvatar(
          backgroundImage: AssetImage('assets/images/test.jpg'),
        ),
        onTap: () {
          print('Card Clicked');
        },
      ),
    ),
    

提交回复
热议问题