//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
//画背景
var paint = Paint()
…isAntiAlias = false
…strokeWidth=30.0
…color = Colors.red;
canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,60.0), paint…strokeCap);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
//画背景
var paint = Paint()
…isAntiAlias = false
…strokeWidth=30.0
…color = Colors.red;
canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,70.0), paint…strokeCap);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
isAntiAlias=true(消除锯齿)
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
//画背景
var paint = Paint()
…isAntiAlias = true
…strokeWidth=30.0
…color = Colors.red;
canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,60.0), paint…strokeCap);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
//画背景
var paint = Paint()
…isAntiAlias = true
…strokeWidth=30.0
…color = Colors.red;
canvas.drawLine(Offset(50.0, 50.0), Offset(100.0,70.0), paint…strokeCap);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
strokeWidth(画笔宽度)
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
//画背景
var paint = Paint()
…isAntiAlias = true
…color = Colors.red;
canvas.drawLine(Offset(50.0, 46.0), Offset(200.0,46.0), paint…strokeCap…strokeWidth=4.0);
canvas.drawLine(Offset(50.0, 60.0), Offset(200.0,60.0), paint…strokeCap…strokeWidth=8.0);
canvas.drawLine(Offset(50.0, 80.0), Offset(200.0,