flutter使用InkWell點擊沒有水波紋效果的解決方法
-
InkWell點擊沒有水波紋效果原因,如下所示,就是給InkWell的child設置了顏色,遮擋住了效果
InkWell( splashColor: Colors.cyanAccent, //這是水波紋顏色,不影響效果的 child: Container( color: Colors.white, //這句設置的顏色導致點擊沒有水波紋效果 alignment: Alignment.center, width: double.infinity, height: 50, child: Text('exit'), ), onTap: () { showToast('message'); }, ),
-
解決方法,就是外層使用Ink包裹一下,並在Ink里設置顏色即可
Ink( color: Colors.white, //使用Ink包裹,在這里設置顏色 child: InkWell( splashColor: Colors.cyanAccent, child: Container( alignment: Alignment.center, width: double.infinity, height: 50, child: Text('exit'), ), onTap: () { showToast('message'); }, ), ),
所以,我一般直接使用FlatButton,既可以添加點擊事件,也有水波紋效果。