Flutter 給控件添加點(diǎn)擊事件

需求個(gè)人中心item 需要點(diǎn)擊,但是它的最外層是Column 布局,這時(shí)候只需要外層加一個(gè)InkWell 就能實(shí)現(xiàn)了(在flutter 開(kāi)發(fā)中用InkWell或者GestureDetector將某個(gè)組件包起來(lái),可添加點(diǎn)擊事件)
代碼如下:

_itemSection(String title, Widget image){
    return InkWell(
      onTap: (){
        print("點(diǎn)擊了 $title");

      },
      child: Column(
        children: <Widget>[
          Container(
            alignment: Alignment.centerLeft,
            height: 40,
            padding: EdgeInsets.only(left: 17,right: 17),
            decoration: new BoxDecoration(
                color:Color(0xFF0D1020),
                borderRadius: BorderRadius.circular(5)
            ),
            child: Row(
              children: <Widget>[
                image,
                Expanded(
                  child: Container(
                    padding: EdgeInsets.only(left: 14,),
                    child: Text(
                      title,
                      style: TextStyle(
                          color: Colors.white
                      ),
                    ),
                  ),
                ),
                LoadAssetImage("my/my_right_arrow",width: 6,height: 10,)
              ],
            ),
          )
        ],
      ),
    );
  }

注意事項(xiàng):

  1. 使用 InkWell 時(shí)內(nèi)外層均不建議添加背景色,InkWell 默認(rèn)的水波紋顏色很淺,背景色會(huì)遮擋波紋效果;
  2. 通過(guò)修改 splashColor: Colors.greenAccent, 屬性可以動(dòng)態(tài)修改水波紋的波紋顏色,但如果修改高亮色屬性 highlightColor,則相當(dāng)于修改背景色;
  3. 請(qǐng)一定添加 InWell 手勢(shì)觸發(fā)事件,如 onTap 等。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容