简体   繁体   English

如何在 flutter 中将边框颜色显示为圆形?

[英]How display a border color to a circle in flutter?

I would like to know how it is possible to set a border color of a circle.我想知道如何设置圆形的边框颜色。 My code is:我的代码是:

child: Container(
  child: ClipOval(
    child: Container(
      color: colorList[index],
      height: 30.0,
      width: 30.0,
      child: Center(
        child: new Text((index+1).toString(),
          style: TextStyle(color: Colors.white, fontSize: 24,fontWeight: FontWeight.w500),
            textAlign: TextAlign.center),
      ),
    ),
  ),
),

So i use Clipoval for display a circle, i can set color of the circle and text in it without any problem but i need set the color of border of the circle.所以我使用 Clipoval 来显示一个圆圈,我可以毫无问题地设置圆圈的颜色和其中的文本,但我需要设置圆圈边框的颜色。 I want to display white circle with red border on white background我想在白色背景上显示带有红色边框的白色圆圈

You can use BoxDecoration on your Container to achieve this.您可以在 Container 上使用BoxDecoration来实现此目的。 You don't need a ClipOval, instead you can apply shape parameter on BoxDecoration to get circular appearance.您不需要 ClipOval,而是可以在 BoxDecoration 上应用 shape 参数来获得圆形外观。

Container(
   child: Container(
      decoration: BoxDecoration(
         color: Colors.grey,
         border: Border.all(color: Colors.red),
         shape: BoxShape.circle,
      ),
      height: 30.0,
      width: 30.0,
      child: Center(
         // Your Widget
      ),
   ),
),

Another thing to consider is the CustomPaint class.要考虑的另一件事是CustomPaint class。 Here is an example:这是一个例子:

class CurvePainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint();
    paint.color = Colors.deepOrange;
    paint.strokeWidth = 5;
    paint.style = PaintingStyle.stroke;
    canvas.drawCircle(
        Offset(size.width / 2, size.height / 2), 80, paint);

  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}

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

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