简体   繁体   English

如何在 flutter 中创建带边框的圆形容器?

[英]How to create circle container with border in flutter?

As you can notice, the background color of the decoration is slightly overflowing the circular border.如您所见,装饰的背景颜色略微溢出了圆形边框。 I've tried in different ways (eg using ClipOval) but the result is always the same.我尝试过不同的方式(例如使用 ClipOval),但结果总是一样的。

在此处输入图像描述

    I have just faced the same issue...
    Easy workaround:

     Container(
        width: 28,
        height: 28,
        decoration: BoxDecoration(
          color: Colors.green.withOpacity(0.25), // border color
          shape: BoxShape.circle,
        ),
        child: Padding(
          padding: EdgeInsets.all(2), // border width
          child: Container( // or ClipRRect if you need to clip the content
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.blue, // inner circle color
            ),
            child: Container(), // inner content
          ),
        ),
      ),

Ref:参考:

Container(
            height: 200,
            width: 200,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(width: 1, color: Colors.red)
            ),
          ),

Container( height:80, width:80, decoration:BoxDecoration(容器(高度:80,宽度:80,装饰:BoxDecoration(

          color:Colors.red,
        borderRadius:BorderRadius.circular(50),
          border:Border.all(
          color:Colors.white,
          width:8
          ),
         
        ),
        child:
        Center(child:
        Text("4",
                  style:TextStyle(
                  color:Colors.white,
                    fontWeight:FontWeight.bold,
                    fontSize:20
                  )))
    

[Container with border][1] [1]: https://i.stack.imgur.com/N81gH.png [带边框的容器][1] [1]: https://i.stack.imgur.com/N81gH.png

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

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