flutter canvas 简单绘画直线

it2022-05-05  114

1. 定义一个class

class MyPainter extends CustomPainter { Color lineColor; double width; MyPainter({this.lineColor, this.width}); @override void paint(Canvas canvas, Size size) { Paint _paint = new Paint() ..color = Colors.blueAccent ..strokeCap = StrokeCap.round ..isAntiAlias = true ..strokeWidth = 5.0 ..style = PaintingStyle.stroke; canvas.drawLine(Offset(20.0, 20.0), Offset(100.0, 100.0), _paint); } @override bool shouldRepaint(CustomPainter oldDelegate) => false; }

2. 使用

Container( child:CustomPaint( foregroundPainter: new MyPainter( lineColor: Colors.lightBlueAccent, width: 8.0, ), ), ),

转载于:https://www.cnblogs.com/john-hwd/p/11202477.html

相关资源:DirectX修复工具V4.0增强版

最新回复(0)