簡體   English   中英

顫振:畫半圓

[英]Flutter: draw half circle

這樣的半圓怎么畫? 拜托,我不想要一個容器小部件並改變它的半徑

在此處輸入圖片說明

我不明白你在“我不想要一個容器小部件並改變它的半徑”中的意思,但這是我創建半圓的方法:

class Test extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          body: new Container(
            padding: EdgeInsets.all(64.0),
            child: new Column(
              children: <Widget>[
                new ClipPath(
                  clipper: new CustomHalfCircleClipper(),
                  child: new Container(
                    height: 300.0,
                    width: 300.0,
                    decoration: new BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(150.0) ),
                  ),
                )
              ],
            ),
          ),
        );
      }
    }

    class CustomHalfCircleClipper extends CustomClipper<Path> {
      @override
      Path getClip(Size size) {
        final Path path = new Path();
        path.lineTo(0.0, size.height / 2);
        path.lineTo(size.width, size.height / 2);
        path.lineTo(size.width, 0);
        return path;
      }
      @override
      bool shouldReclip(CustomClipper<Path> oldClipper) {
        return true;
      }
    }

你只需要一個Container ,EASY PEASY:

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

您可以使用 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;
  }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM