需求個(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):
- 使用 InkWell 時(shí)內(nèi)外層均不建議添加背景色,InkWell 默認(rèn)的水波紋顏色很淺,背景色會(huì)遮擋波紋效果;
- 通過(guò)修改 splashColor: Colors.greenAccent, 屬性可以動(dòng)態(tài)修改水波紋的波紋顏色,但如果修改高亮色屬性 highlightColor,則相當(dāng)于修改背景色;
- 請(qǐng)一定添加 InWell 手勢(shì)觸發(fā)事件,如 onTap 等。