You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
818 B

4 years ago
import 'dart:math';
import 'package:flutter/material.dart';
class BackGroundClipper extends CustomClipper<Path> {
///取值为 -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<Path> oldClipper) {
return true;
}
}