flutter 如何使用CustomClipper在左侧制作多个尖边?

jdg4fx2g  于 2022-12-05  发布在  Flutter
关注(0)|答案(2)|浏览(211)

我正试图使多个尖边在左侧。

class CustomClipPath extends CustomClipper<Path> {

@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width, 0.0);

var curYPos = 0.0;
var curXPos = size.width;
var increment = size.height / 30;
while (curYPos < size.height) {
  curYPos += increment;
  curXPos = curXPos == size.width ? size.width - 8 : size.width;
  path.lineTo(curXPos, curYPos);
}
path.lineTo(0, size.height);

return path;
 }

@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

然而,而不是在左侧的多个尖锐的边缘,我得到了右侧的多个尖锐的边缘,如下图:Text

ztigrdn8

ztigrdn81#

这是一个裁剪器,使用的是孩子的左侧。

class CustomClipPath extends CustomClipper<Path> {

  @override
  Path getClip(Size size) {
    Path path = Path();

    var curYPos = 0.0;
    var curXPos = 0.0;
    var increment = size.height / 30;
    while (curYPos < size.height) {
      curYPos += increment;
      curXPos = curXPos == 0.0 ? 8.0 : 0.0;
      path.lineTo(curXPos, curYPos);
    }
    path.lineTo(size.width, size.height);
    path.lineTo(size.width, 0.0);
    path.close();

    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
jv4diomz

jv4diomz2#

试试这个

class CustomClipPath extends CustomClipper<Path> {

@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width, 0.0);

var curYPos = 0.0;
var curXPos = 0.0;
path.lineTo(0.0, 0.0);  
var increment = size.height / 30;
while (curYPos < size.height) {
  curYPos += increment;
  curXPos = curXPos == 0 ?  8 : 0;
  path.lineTo(curXPos, curYPos);
}
path.lineTo(size.width, size.height);
path.lineTo(size.width, 0.0);
return path;
}

@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

相关问题