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

S.D*_*.D. 29 flutter

你怎么会FlatButton成为一个圆形边框的按钮?我使用圆形边框形状,RoundedRectangleBorder但不知何故需要为边框着色.

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

带有圆角按钮的按钮的示例: 图片

wiz*_*mea 73

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)),
        )
Run Code Online (Sandbox Code Playgroud)

  • FlatButton、RaishedButton 和 OutlineButton 已分别替换为 TextButton、ElevatedButton 和 OutlinedButton。 (7认同)

Rém*_*let 56

OutlineButton而不是FlatButton.

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

  • @Farhana,要设置 OulinedButton 的边框颜色,请使用其属性 borderSide: BorderSide(color: Colors.blue) (4认同)
  • @egidiocs 我找不到 borderSide 属性。在哪里设置这个属性? (4认同)
  • @RemiRousselet 如何更改边框颜色? (3认同)
  • @Hasen 那么,使用相同的逻辑,我们可以将 `MaterialButton` 用于所有内容 (3认同)
  • FlatButton、RaishedButton 和 OutlineButton 已分别替换为 TextButton、ElevatedButton 和 OutlinedButton。 (2认同)

小智 14

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

// this property adds outline border color
Run Code Online (Sandbox Code Playgroud)

  • 如果有人想知道为什么颜色不出现,就我而言,这是因为您需要传递一个`onPress`而不是null。 (3认同)

小智 14

使用StadiumBorder形状

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

  • 对于任何不知道的人来说,StadiumBorder 是一个末端有半圆的盒子(我猜就像体育场的跑道) (7认同)

小智 5

所以我确实使用了完整的样式和边框颜色,如下所示:

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