有時(shí)候可能不想要button的默認(rèn)間距,想要精確的根據(jù)設(shè)計(jì)圖布局,如下
Container(
color: Colors.red,
child: TextButton(
child: Text('TextButton',style: TextStyle(color: Colors.white),),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.blue),
),
onPressed: (){
},
),
)

image.png
你會(huì)看到,
Container不是完全包裹的,而且button也是有一些內(nèi)間距的很明顯,肯定是通過
style來設(shè)置唄, ButtonStyle里加上
padding: MaterialStateProperty.all(EdgeInsets.zero),

image.png
發(fā)現(xiàn)左右間距確實(shí)沒了,但是上下沒啥變化·
里面還有個(gè)
最小size屬性,來設(shè)置看看
minimumSize: MaterialStateProperty.all(Size.zero),

image.png
這下都沒了,但是
Container的包裹還是原樣,這是因?yàn)橛悬c(diǎn)擊的size,再設(shè)置一下
tapTargetSize: MaterialTapTargetSize.shrinkWrap,

image.png
這下真就沒有間距了
如下設(shè)置指定大小
fixedSize: MaterialStateProperty.all(Size(100,44))

image.png