import 'dart:math'; import 'package:flutter/material.dart'; class BackGroundClipper extends CustomClipper { ///取值为 -1 ~ 1.0 double moveFlag = 0; BackGroundClipper(this.moveFlag); @override Path getClip(Size size) { //创建 Path Path path = Path(); //移动到点 P0点 也是曲线的起点 path.lineTo(0, size.height * 0.2); //计算控制点 P1 的坐标 double xCenter = size.width * 0.5 + (size.width * 0.6 + 1) * sin(moveFlag * pi); double yCenter = size.height * 0.2 + 69 * cos(moveFlag*pi); //构建 二阶贝塞尔曲线 path.quadraticBezierTo(xCenter, yCenter, size.width, size.height * 0.2); path.lineTo(size.width, 0); return path; } @override bool shouldReclip(CustomClipper oldClipper) { return true; } }