【发布时间】:2019-04-12 10:01:10
【问题描述】:
我希望为 AnimatedContainer 和 ClipPath 在 y 轴上移动制作动画。
这是我当前的代码:
class Clip extends StatelessWidget {
final double height;
Clip(this.height);
@override
Widget build(BuildContext context) {
return Scaffold(
body: ClipPath(
clipper: RoundedClipper(height),
child: AnimatedContainer(
duration: Duration(seconds: 5),
height: height,
color: Colors.amber,
),
),
);
}
}
class RoundedClipper extends CustomClipper<Path> {
final double height;
RoundedClipper(this.height);
@override
Path getClip(Size size) {
var path = Path();
path.lineTo(0.0, height - 200);
path.quadraticBezierTo(
size.width / 2,
height,
size.width,
height - 200,
);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}
根据我传递给此类的高度,AnimatedContainer 将在两者之间通过动画进行转换,而剪辑器不会进行动画处理。
看起来是这样的:
我尝试用 AnimatedContainer 包装剪裁器并在其上设置动画,但没有成功。
如何使剪切路径与 AnimatedContainer 一起垂直动画?
感谢任何愿意提供帮助的人
【问题讨论】: