flutter使用InkWell點擊沒有水波紋效果的解決方法


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,既可以添加點擊事件,也有水波紋效果。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM