Flutter:解决MaterialButton存在最小高度问题

如果MaterialButton小于48的时候,顶部就会存在一定的margin,这是因为MaterialButton继承了RawMaterialButton,RawMaterialButton有这么一段代码

    Size minSize;
    switch (widget.materialTapTargetSize) {
      case MaterialTapTargetSize.padded:
        minSize = const Size(48.0, 48.0);
        break;
      case MaterialTapTargetSize.shrinkWrap:
        minSize = Size.zero;
        break;
    }

可以通过设置materialTapTargetSize: MaterialTapTargetSize.shrinkWrap即可实现。

MaterialButton(
  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  height: 28,
  minWidth: 69,
  padding: EdgeInsets.all(0),
  color: Color(0xFFEC4020),
  textColor: Colors.white,
  shape: RoundedRectangleBorder(
      borderRadius:
      BorderRadius.all(Radius.circular(14))),
  onPressed: () {},
  child: Text("点击"),
)

推荐阅读更多精彩内容