flutter

Flutter之ClipPath组件

2019-03-27  本文已影响1人  习惯了_就好
/**
 * 路径裁剪
 *
 * ClipPath({
 * Key key,
 * this.clipper, //裁剪路径
 * this.clipBehavior = Clip.antiAlias,
 * Widget child
 * })
 */
class TriangleCliper extends CustomClipper<Path> {
  //获取裁剪范围
  @override
  Path getClip(Size size) {
    //左上角为(0,0)
    var path = Path();
    path.moveTo(50.0, 50.0);//起始点
    path.lineTo(50.0, 0);//(50.0,50.0)->(50.0, 0)
    path.lineTo(100.0, 100.0);//(50.0,0)->(100.0, 100.0)
    path.close();//
    return path;
  }

  //是否重新裁剪
  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }

}


body: Center(
            child: ClipPath(
              clipper: TriangleCliper(),
              child: Image.asset(
                "images/app.png",
                width: 100.0,
                height: 100.0,
                fit: BoxFit.cover,
              ),
            ),
          )
上一篇 下一篇

猜你喜欢

热点阅读