如何在Flutter上为MaterialButton设置圆角边框?

时间:2019-02-22 13:44:24

标签: dart flutter widget material-ui

我正在尝试为MaterialButton设置圆角边框,为此,我设置了RoundedRectangleBorder来塑造属性的MaterialButton,问题是它没有效果。< / p>

代码:

  Widget _showNeedHelpButton() {
    return new Padding(      
      padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
      child: new MaterialButton(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20.0))),
        elevation: 5.0,
        minWidth: 200.0,
        height: 35,
        color: Color(0xFF801E48),
        child: new Text('Preciso de ajuda',
            style: new TextStyle(fontSize: 16.0, color: Colors.white)),
        onPressed: () {
          setState(() {
            _isNeedHelp = true;
          });
        },
      ),
    );
  }

结果:

enter image description here

2 个答案:

答案 0 :(得分:2)

如果您需要使用MaterialButton()-您需要使用Material小部件扭曲按钮以获得所需的行为。

    Widget _showNeedHelpButton() {
    return Padding(
      padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
      child: Material(  //Wrap with Material
        shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(22.0) ),
        elevation: 18.0,
        color: Color(0xFF801E48),
        clipBehavior: Clip.antiAlias, // Add This
        child: MaterialButton(
          minWidth: 200.0,
          height: 35,
          color: Color(0xFF801E48),
          child: new Text('Preciso de ajuda',
              style: new TextStyle(fontSize: 16.0, color: Colors.white)),
          onPressed: () {
//          setState(() {
//            _isNeedHelp = true;
//          });
          },
        ),
      ),
    );
  }

输出: enter image description here

更新:

  minWidth: 200.0,
  height: 95,

enter image description here

答案 1 :(得分:0)

您是否尝试过将其包装在ClipRRect()中?

ClipRRect(
  borderRadius: BorderRadius.all(Radius.circular(20.0)),
  child: MaterialButton(...),
),

您可以在此处找到文档:ClipRRect()