颤振:画半圈

时间:2019-02-28 22:28:53

标签: dart flutter flutter-layout

如何绘制这样的半圆? 请,我不想使用Container小部件并更改其半径

enter image description here

3 个答案:

答案 0 :(得分:0)

我不明白您在“我不想使用容器小部件并更改其半径”中的意思,但是这是我创建一个半圆的方法:

https://github.com/robfig/cron

答案 1 :(得分:0)

您可以使用CustomPainter。

class HalfCircle extends CustomPainter{
  @override
  void paint(Canvas canvas, Size size) {

    canvas.drawArc(Rect.fromCircle(center:Offset(size.width/2,size.height/2),radius: 97), 3.14, 3.14, false, customPaint());
    canvas.drawPath(getTrianglePath(size,20, 15), customPaint());
  }

  Path getTrianglePath(Size size,double x, double y) {
    return Path()
      ..moveTo(size.width/2, 0)
      ..lineTo(size.width/2+x, y)
      ..lineTo(size.width/2, y)
      ..lineTo(size.width/2-x, y);
  }

  Paint customPaint(){
    Paint paint = Paint();
    paint.color = Color(0xff2EA760);
    paint.isAntiAlias = true;
    paint.strokeWidth = 10;
    return paint;
  }

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

}

答案 2 :(得分:0)

你只需要一个Container,简单易懂:

Container(
      decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(100),
              topLeft: Radius.circular(100)),
         color: Colors.red,
         shape: BoxShape.rectangle,
     ),
     height: 35,
     width: 35,
),