Flutter - 无间距Button

有时候可能不想要button的默认间距,想要精确的根据设计图布局,如下

Container(
              color: Colors.red,
              child: TextButton(
                child: Text('TextButton',style: TextStyle(color: Colors.white),),
                style: ButtonStyle(
                    backgroundColor: MaterialStateProperty.all(Colors.blue),
                ),
                onPressed: (){

                },
              ),
            )

image.png

你会看到,Container不是完全包裹的,而且button也是有一些内间距的
很明显,肯定是通过style来设置呗, ButtonStyle里加上

padding: MaterialStateProperty.all(EdgeInsets.zero),

image.png

发现左右间距确实没了,但是上下没啥变化·
里面还有个最小size属性,来设置看看

minimumSize: MaterialStateProperty.all(Size.zero),

image.png

这下都没了,但是Container的包裹还是原样,这是因为有点击的size,再设置一下

tapTargetSize: MaterialTapTargetSize.shrinkWrap,
image.png

这下真就没有间距了
如下设置指定大小

fixedSize: MaterialStateProperty.all(Size(100,44))
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容