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

sczxawaw  于 2023-06-19  发布在  Flutter
关注(0)|答案(3)|浏览(183)

正如您所注意到的,装饰的背景色略微溢出了圆形边框。我尝试了不同的方法(例如:使用ClipOval),但结果始终相同。

sycxhyv7

sycxhyv71#

我刚刚也遇到了同样的问题。简单的解决方法:

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
          ),
        ),
      ),

Reference

tyu7yeag

tyu7yeag2#

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

ztyzrc3y3#

Container(
            height:80,
            width:80,
            decoration: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
                      )))

带边框的容器

相关问题