本文介绍了Flutter:您如何使卡片可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个像new Card(child: new Text('My cool card'))这样的简单Card,并且我希望能够单击它的任意位置以运行某些功能,但Card并没有onPressed方法.我可以在底部添加一个按钮,但这对这种情况并不理想.

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?

推荐答案

Flutter在属性上使用合成.将所需的小部件包装为可点击的小部件,以实现所需的功能.

Flutter use composition over properties.Wrap the desired widget into a clickable one to achieve what you need.

一些可点击的小部件: GestureDetector InkWell InkResponse .

Some clickable widgets : GestureDetector, InkWell, InkResponse.

new GestureDetector(
  onTap: ()=> ......,
  child: new Card(...),
);

这篇关于Flutter:您如何使卡片可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 09:28