美文网首页
canvas绘制椭圆

canvas绘制椭圆

作者: 心旷则神怡 | 来源:发表于2022-05-27 16:57 被阅读0次

    canvas和paiter搭配使用;

    class DrawPainter extends CustomPainter {
      final Rect? rect;
      DrawPainter(this.rect,);
      @override
      void paint(Canvas canvas, Size size) {
        // TODO: implement paint
        Paint paint = Paint();
        paint.color = Colors.white;
        paint.style = PaintingStyle.stroke;
        paint.strokeWidth = 5;
        canvas.drawOval(Rect.fromLTWH(rect!.left, rect!.top, rect!.width, rect!.height), paint);
      }
    
      @override
      bool shouldRepaint(covariant CustomPainter oldDelegate) {
        // TODO: implement shouldRepaint
        return false;
      }
    }
    

    调用:

    Positioned(
         child: CustomPaint(
           painter: DrawPainter(Rect.fromLTWH(0, 5, width - 10, height)),
        ),
    )
    

    相关文章

      网友评论

          本文标题:canvas绘制椭圆

          本文链接:https://www.haomeiwen.com/subject/uexvprtx.html