Rect rect=Rect.fromLTRB(0.0, 0.0, size.width, size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromCenter({ Offset center, double width, double height })
center | 矩形中心相对于原点偏移量 |
width | 矩形宽度 |
height | 矩形高度 |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromCenter(center: Offset(size.width/2,size.height/2),width:size.width/2,height:size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromLTWH(double left, double top, double width, double height)
left | 矩形最左边相对于原点偏移量 |
top | 矩形最顶部相对于原点偏移量 |
width | 矩形宽度 |
height | 矩形高度 |
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=0.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromLTWH(0.0, 0.0, size.width/2, size.height/2);
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Rect.fromPoints(Offset a, Offset b) : this.fromLTRB(
math.min(a.dx, b.dx),
math.min(a.dy, b.dy),
math.max(a.dx, b.dx),
math.max(a.dy, b.dy),
);
a | 相对于原点x方向上的偏移范围 |
b | 相对于原点y方向上的偏移范围 |
下面三种写法效果一样(主要是取x或y方向上偏移量的范围)
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
…isAntiAlias = true
…strokeWidth=1.0
…color=Colors.redAccent
…invertColors=false;
Rect rect=Rect.fromPoints(Offset(size.width, 0.0),Offset(0,size.height));
canvas.drawArc(rect, 0.0, 2*pi/4, false, paint);
}
//在实际场景中正确利用此回调可以避免重绘开销,本示例我们简单的返回true
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
class MyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint