我有以下自定義畫家,我想繞過路徑的任何邊緣
如果你有幫助,我將不勝感激

uj5u.com熱心網友回復:
你可以使用這個CustomPainter:
class CustomDraw extends CustomPainter {
late Paint painter;
late double radius;
CustomDraw(Color color, {this.radius = 0}) {
painter = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 10
..strokeCap = StrokeCap.round
..color = color;
}
@override
void paint(Canvas canvas, Size size) {
var path = Path();
path.moveTo(size.width, 0);
path.lineTo(0 radius, 0);
path.cubicTo(0 radius, 0, 0, 0, 0, radius);
path.lineTo(0, 35 - radius);
path.cubicTo(0, 35 - radius, 0, 35, radius, 35);
path.lineTo(size.width - radius, 35);
path.cubicTo(
size.width - radius, 35, size.width, 35, size.width, 35 radius);
path.lineTo(size.width, 35 35 - radius);
path.cubicTo(size.width, 35 35 - radius, size.width, 35 35,
size.width - radius, 35 35);
path.lineTo(0, 35 35);
canvas.drawPath(path, painter);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
像這樣使用它:
CustomPaint(
painter: CustomDraw(Colors.red, radius: 16),
child: SizedBox(
height: 100,
width: 200,
),
),

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/535046.html
上一篇:如何自定義linter規則?
