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

时间:2021-03-03 04:37:32

标签: flutter dart containers border

如您所见,装饰的背景颜色略微溢出圆形边框。我尝试过不同的方法(例如使用 ClipOval),但结果总是一样的。

enter image description here

2 个答案:

答案 0 :(得分:3)

    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:

答案 1 :(得分:0)

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