0

我有一个自定义快剪(五角形),但我需要把所有的角都弄圆一点。

这是我的 Clipper 代码:

class Pentagon extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    final path = Path();
    path.lineTo(size.width * 0.5, 0);
    path.lineTo(size.width, size.height * 0.38);  
    path.lineTo(size.width * 0.82, size.height);
    path.lineTo(size.width * 0.18, size.height);
    path.lineTo(0, size.height * 0.38);
    path.lineTo(size.width * 0.5, 0);

    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
4

2 回答 2

0

用于StrokeCap.round圆角,演示示例:

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

  Paint paint_0 = new Paint()
      ..color = Color.fromARGB(255, 33, 150, 243)
      ..style = PaintingStyle.fill
      ..strokeWidth = 8.34;
      ..strokeCap = StrokeCap.round;

         
    Path path_0 = Path();
    path_0.moveTo(size.width*0.25,size.height*0.50);
    path_0.lineTo(size.width*0.31,size.height*0.40);
    path_0.lineTo(size.width*0.38,size.height*0.40);
    path_0.lineTo(size.width*0.44,size.height*0.50);
    path_0.lineTo(size.width*0.34,size.height*0.60);
    path_0.lineTo(size.width*0.25,size.height*0.50);
    path_0.close();

    canvas.drawPath(path_0, paint_0);
  
    
  }

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

并称它为:

child: CustomPaint(
  size: Size(800,500), //You can Replace this with your desired WIDTH and HEIGHT
  painter: CustomPainterPentagon(),
),
于 2021-01-27T08:49:28.413 回答
0

尝试使用此工具绘制自定义形状,fluttershapemaker

于 2021-01-27T08:44:06.043 回答