创建一个带圆角边框的按钮

时间:2018-04-29 04:28:53

标签: flutter

如何将FlatButton放入带有圆形边框的按钮?我使用RoundedRectangleBorder的圆形边框形状,但不知何故需要为边框着色。

new FlatButton(
  child: new Text("Button text),
  onPressed: null,
  shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)

带圆角按钮的按钮的示例:image

7 个答案:

答案 0 :(得分:38)

使用OutlineButton代替FlatButton

new OutlineButton(
  child: new Text("Button text"),
  onPressed: null,
  shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)

答案 1 :(得分:7)

使用StadiumBorder形状

              OutlineButton(
                onPressed: () {},
                child: Text("Follow"),
                borderSide: BorderSide(color: Colors.blue),
                shape: StadiumBorder(),
              )

答案 2 :(得分:6)

new OutlineButton(  
 child: new Text("blue outline") ,
   borderSide: BorderSide(color: Colors.blue),
  ),

// this property adds outline border color

答案 3 :(得分:2)

要实现带有边框颜色的圆角边框按钮,请使用此

OutlineButton(
                    child: new Text("Button Text"),borderSide: BorderSide(color: Colors.blue),
                    onPressed: null,
                    shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(20.0))
                ),

答案 4 :(得分:1)

如果您不想使用OutlineButton并希望坚持使用普通RaisedButton,则可以将按钮包裹在ClipRRectClipOval中,如下所示:

ClipRRect(
  borderRadius: BorderRadius.circular(40),
  child: RaisedButton(
    child: Text("Button"),
    onPressed: () {},
  ),
),

答案 5 :(得分:0)

所以我确实使用了这样的完整样式和边框颜色:

new OutlineButton(
    shape: StadiumBorder(),
    textColor: Colors.blue,
    child: Text('Button Text'),
    borderSide: BorderSide(
        color: Colors.blue, style: BorderStyle.solid, 
        width: 1),
    onPressed: () {},
)

答案 6 :(得分:0)

FlatButton(
          onPressed: null,
          child: Text('Button', style: TextStyle(
              color: Colors.blue
            )
          ),
          textColor: MyColor.white,
          shape: RoundedRectangleBorder(side: BorderSide(
            color: Colors.blue,
            width: 1,
            style: BorderStyle.solid
          ), borderRadius: BorderRadius.circular(50)),
        )