我做了2个定制画家
1.
class DrawTriangle1 extends CustomPainter {
DrawTriangle1() {
painter = Paint()
..shader =
LinearGradient(colors: [Colors.red, Colors.white]).createShader(rect)
..style = PaintingStyle.fill;
}
@override
void paint(Canvas canvas, Size size) {
var path = Path();
path.moveTo(0, 0);
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height / 2);
path.close();
canvas.drawPath(path, painter);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
class DrawTriangle2 extends CustomPainter {
DrawTriangle2() {
painter = Paint()
..shader = LinearGradient(colors: [
Color(0xfffff),
Color(0xff076585),
]).createShader(rect)
..style = PaintingStyle.fill;
}
@override
void paint(Canvas canvas, Size size) {
var path = Path();
path.lineTo(size.width / 2, size.height / 4);
path.lineTo(0, size.height / 2);
path.close();
canvas.drawPath(path, painter);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
如果我使用自定义画家制作单个形状。画家从页面开始绘制它。
ListView(
children: <Widget>[
CustomPaint(
painter: DrawTriangle1(),
size: Size(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height), ,
)
],
)
但是如果我像这样将另一个添加到列表视图中。第二个三角形从第一个屏幕的底部开始。
ListView(
children: <Widget>[
CustomPaint(
painter: DrawTriangle1(),
size: Size(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height),
),
CustomPaint(
painter: DrawTriangle2(),
size: Size(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height),
)
],
),
我如何使它们具有相同的起点?