flutter canvas 简单绘画直线
Posted john-hwd
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flutter canvas 简单绘画直线相关的知识,希望对你有一定的参考价值。
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, ), ), ),
以上是关于flutter canvas 简单绘画直线的主要内容,如果未能解决你的问题,请参考以下文章
canvas入门,一篇博文带你学会用代码绘画,直击实战案例!