gpt4 book ai didi

android - ( flutter )CustomPaint 小部件的弯曲边缘

转载 作者:搜寻专家 更新时间:2023-11-01 09:19:19 26 4
gpt4 key购买 nike

这就是我想要构建的:

(只看 appBar 的形状而不是内容)

enter image description here

这是我的:

enter image description here

我希望边缘是弯曲的,而不是那么尖锐。

这是我的 CustomPaint 代码:

class LogoPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint();
paint.color = Colors.blue;
var path = Path();
path.lineTo(0, size.height - size.height / 5);
path.lineTo(size.width / 1.2, size.height);
path.lineTo(size.width, size.height - size.height / 5);
path.lineTo(size.width, 0);
path.close();
canvas.drawPath(path, paint);
}

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

如何实现这种弯曲边缘?

我尝试了 point.arcToPoint()point.quadraticBezierTo(),但没有成功。

最佳答案

这并不完美,但您可以稍微调整一下数字:

class LogoPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint();
paint.color = Colors.blue;
var path = Path();
path.lineTo(0, size.height - size.height / 5);
path.lineTo(size.width / 1.2, size.height);
//Added this line
path.relativeQuadraticBezierTo(15, 3, 30, -5);
path.lineTo(size.width, size.height - size.height / 5);
path.lineTo(size.width, 0);
path.close();
canvas.drawPath(path, paint);
}

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

这段代码给出了这样的结果: Curved bezier app bar background

关于android - ( flutter )CustomPaint 小部件的弯曲边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57877602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com