我是 Flutter 的新手,我遇到了一个问题。我必须根据给定的高度值裁剪 png。这适用于我制作的这个类(class):
class ScaleClipper extends CustomClipper<Rect> {
double value;
@override
Rect getClip(Size size) {
Rect rect = Rect.fromLTWH(0.0, 0.0 + value, size.width, size.height);
return rect;
}
@override
bool shouldReclip(ScaleClipper oldClipper) {
return true;
}
ScaleClipper(double value) {
this.value = value;
}
}
现在我想为图像中的变化设置动画。我试图将它包装在此处提到的小部件中:https://flutter.io/docs/development/ui/widgets/animation 但我没有让它正常工作。 这是我显示图像的小部件:
ClipRect(
clipper: ScaleClipper(value),
child: Container(
margin: new EdgeInsets.only(
left: 30.0, top: 30.0, right: 20.0, bottom: 30.0),
width: 150.0,
height: 420.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/image.png"),
fit: BoxFit.contain))),
),
我是否需要改变我解决问题的方法,或者我可以为图像的剪辑设置动画?
最佳答案
我为 future 的新人找到了答案。你可以像这样使用一个简单的补间动画
controller = AnimationController(
duration: const Duration(milliseconds: 1000), vsync: this);
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
fracturedValue = desiredClipValue * animation.value;
});
});
关于animation - 带有动画的 Flutter 剪辑 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53613116/