imgclipperpath.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:flutter/material.dart';
  2. /// 创建剪裁路径
  3. class ImgClipperPath extends CustomClipper<Path> {
  4. final double navbarH;
  5. ImgClipperPath(this.navbarH);
  6. @override
  7. Path getClip(Size size) {
  8. var path = Path();
  9. // 连接到距离左上角3/4处
  10. path.lineTo(0.0, size.height / 2);
  11. // 第一个控制点
  12. var firstControlPoint = Offset(0, size.height);
  13. // 目标点是底部中间点
  14. var firstPoint = Offset(size.width / 3,(size.height/7)*6);
  15. path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
  16. firstPoint.dx, firstPoint.dy);
  17. // 第二个控制点
  18. var secondControlPoint = Offset(size.width, size.height);
  19. // 目标点是右上角 3/4 处
  20. var secondPoint = Offset(size.width, size.height );
  21. path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
  22. secondPoint.dx, secondPoint.dy);
  23. // 连接到右上角
  24. path.lineTo(size.width, 0.0);
  25. // 闭合
  26. path.close();
  27. // 返回剪裁路径
  28. return path;
  29. }
  30. // @override
  31. // Path getClip(Size size) {
  32. // Path path = Path();
  33. //
  34. // path.lineTo(0, 56+navbarH-26);
  35. // path.arcToPoint(
  36. // Offset(26, 56+ navbarH-26),
  37. // radius:const Radius.circular(26),
  38. // clockwise: true);
  39. // path.lineTo(26, 56+navbarH);
  40. // path.lineTo(26, size.height);
  41. // // path.close();
  42. // return path;
  43. // }
  44. @override
  45. bool shouldReclip(CustomClipper<Path> oldClipper) => oldClipper.hashCode != this.hashCode;
  46. }