[英]Custom Shape Issue Flutter
I'm trying to make custom shaped container in flutter, but i can't get symmetric version(symmetric to origin) of shape i made,我正在尝试在 flutter 中制作自定义形状的容器,但我无法获得我制作的形状的对称版本(与原点对称),
class BackgroundClipper1 extends CustomClipper<Path> {
@override
getClip(Size size) {
var path = Path();
path.moveTo(0, 0);
path.lineTo(size.width,0);
path.lineTo(0,size.height);
return path;
}
@override
bool shouldReclip(CustomClipper oldClipper) {
return true;
}
}
. . .
. .
. How i call this in my code.
我如何在我的代码中调用它。
child: ClipPath(
clipper: BackgroundClipper1(),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.5,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.blueAccent])),
)),
Try this..尝试这个..
class MyTriangle extends CustomPainter {
final Color strokeColor;
MyTriangle({this.strokeColor = Colors.white});
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = strokeColor
..style = PaintingStyle.fill;
canvas.drawPath(getTrianglePath(size.width, size.height), paint);
}
Path getTrianglePath(double x, double y) {
return Path()
..moveTo(y, 0)
..lineTo(y, x)
..lineTo(0, x)
..lineTo(y, 0);
}
@override
bool shouldRepaint(MyTriangle oldDelegate) {
return oldDelegate.strokeColor != strokeColor;
}
}
and usage和使用
Container(
width: 150,
height: 150,
child: CustomPaint(painter: MyTriangle(strokeColor: Colors.green)),
)
OUTPUT OUTPUT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.