简体   繁体   English

Flutter Clip-Path 圆角

[英]Flutter Clip-Path rounded corners

i' m stuck with clip-path and i wanna know how can i modify this code:我被剪辑路径困住了,我想知道如何修改这段代码:

class ClipPathClass extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = Path();
    path.lineTo(0.0, size.height - 90);

    var firstControlPoint = Offset(size.width / 4, size.height);

    var firstPoint = Offset(size.width / 2, size.height);
    path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
        firstPoint.dx, firstPoint.dy);
    var secondControlPoint = Offset(size.width - (size.width / 4), size.height);
    var secondPoint = Offset(size.width, size.height - 90);
    path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
        secondPoint.dx, secondPoint.dy);
    path.lineTo(size.width, 0);
    path.close();
    return path;
  }

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

to look like this:看起来像这样:

在此处输入图像描述

cause in my app the code look like this:因为在我的应用程序中,代码如下所示: 在此处输入图像描述

I want that rounded corners.我想要那个圆角。

that because you try to assign control point 1/4 your widht like this:那是因为您尝试像这样将控制点 1/4 分配给您的宽度:

在此处输入图像描述

instead of quadraticBezierTo() 2 times, use cubicTo() 1 times, since its take both of controll point:而不是quadraticBezierTo() 2 次,使用cubicTo() 1 次,因为它需要两个控制点:

在此处输入图像描述

class ClipPathClass extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = Path();
    path.lineTo(0.0, size.height - 90);

    var point = Offset(size.width, size.height - 90);
    var cp1 = Offset(0.0, size.height);
    var cp2 = Offset(size.width, size.height);

    path.cubicTo(cp1.dx, cp1.dy, cp2.dx, cp2.dy, point.dx, point.dy);

    path.lineTo(size.width, 0);
    path.close();
    return path;
  }

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

result:结果:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM