flutter 画一条曲线

1、代码

Container(
  width: 50,
  height: 50,
  child: CustomPaint(
    size: Size(50, 50),
    painter: MyPainter(),
    isComplex: false,
    willChange: false,
    child: Container(),
  ),
);

class MyPainter extends CustomPainter {
  MyPainter();
  ///[定义画笔]
  Paint _paint = Paint()
    ..color = Colors.red //画笔颜色
    ..strokeCap = StrokeCap.round //画笔笔触类型
    ..isAntiAlias = true //是否启动抗锯齿
    ..style = PaintingStyle.stroke //绘画风格,默认为填充
    ..strokeWidth = 1.0; //画笔的宽度

  @override
  void paint(Canvas canvas, Size size) {
    // Rect来确认圆弧的位置,还需要开始的弧度、结束的弧度、是否使用中心点绘制、以及paint弧度
    const PI = 3.1415926;
    Rect rect = Rect.fromCircle(center: Offset(15, 16), radius: 10);
    canvas.drawArc(rect, -2.8, PI, false, _paint);
  }

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

 

 

2、效果图

 

 

你可能感兴趣的:(flutter)