Flutter 里有很多的按鈕組件很多,常見的按鈕組件有:RaisedButton
(按鈕)、MaterialButton
(按鈕)、DropDownButton
(按鈕)、FlatButton
(扁平按鈕)、IconButton
(圖標(biāo)按鈕)、彈出菜單按鈕
(彈出菜單按鈕)、OutlineButton
(輪廓按鈕)、ButtonBar
(輪廓按鈕)、FloatingActionButton
(浮動(dòng)按鈕)、Inkwell
(墨水按鈕)等,實(shí)際項(xiàng)目開發(fā)中可以按自己的需要或者習(xí)慣選擇喜歡的控件。
自己最常用的就是Inkwell
和MaterialButton
,感覺Inkwell
可以實(shí)現(xiàn)所有的布局,基本上都在使用Inkwell
。下面記錄一下遇到的問題:
1、Inkwell取消水波紋
Inkwell
點(diǎn)擊的時(shí)候會(huì)有水波紋一樣的動(dòng)畫效果,但是有些時(shí)候,顯得比較突兀,需要取消這個(gè)效果,加入下面兩個(gè)屬性即可。
highlightColor: Colors.transparent,
radius: 0.0,
2、MaterialButton設(shè)置無法點(diǎn)擊、失效。
使用IgnorePointer
或者AbsorbPointer
包裹按鈕,設(shè)置屬性ignoring
即可。
return IgnorePointer(
ignoring: true,// false無效
child: MaterialButton(
elevation: 0,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
onPressed: () {
},
child: const Align(
alignment: Alignment.center,
child: Text(
"點(diǎn)擊無效",
),
),
),
);