简体   繁体   English

如何为 Flutter 中的 OutlineButton 制作带下划线的边框

[英]How to make an underlined border only for OutlineButton in Flutter

I'm trying to create a button that will display a colored border underneath my image, but only on the bottom side.我正在尝试创建一个按钮,该按钮将在我的图像下方显示彩色边框,但仅在底部显示。 In OutlineButton it only lets me change the whole border, and not one side of it.在 OutlineButton 中,它只允许我更改整个边框,而不是它的一侧。 Can anyone help me!谁能帮我! I need it to be a button because I'm using onPressed(){} to perform my color changing from Colors.transparent to Colors.teal when the user presses the image.我需要它是一个按钮,因为我使用 onPressed(){} 在用户按下图像时执行从 Colors.transparent 到 Colors.teal 的颜色更改。 Thanks!谢谢!

You can simply define the shape property on the FlatButton using Border() .您可以使用Border()简单地在FlatButton上定义 shape 属性。

FlatButton(
  height: 50,
  child: Text('All Posts'),
  shape: Border(
    bottom: BorderSide(color: Colors.black, width: 3)
  ),
  onPressed: (){
    print('You selected all posts');
  },
),

Fixed it.修复。 I changed it to a flatbutton and wrapped the widget in a Material() This allowed me to create a bottom BorderSide, setting it to my color preferences:我将其更改为 flatbutton 并将小部件包装在 Material() 这允许我创建一个底部 BorderSide,将其设置为我的颜色首选项:

bool changeColor = false;

Material(
    shape: Border(
        bottom: BorderSide(
            color: changeColor ? Colors.teal : Colors.transparent, width: 3.0
        )
    ),
    child: FlatButton(
        onPressed: (){
            setState(() {changeColor = !changeColor;});
        },
    ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM