简体   繁体   中英

Flutter CustomClipper Triangle

I have this triangle在此处输入图像描述 and ai would like that its shape would be like this 在此处输入图像描述

Can someone help me? this is my actual code

class TriangleClipperr extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    final path = Path();
    path.lineTo(size.width, 0.0);
    path.lineTo(size.width / 2, size.height);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(TriangleClipperr oldClipper) => false;
}

First, you need to move the current point to middle, then draw rest path.

class TriangleClipperr extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    final path = Path();
    path.moveTo(size.width / 2, 0);
    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);

    path.close();
    return path;
  }

  @override
  bool shouldReclip(TriangleClipperr oldClipper) => false;
}

Shape depends on parent size. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM