gpt4 book ai didi

dart - 如何使用 AnimatedContainer 进行动画变换(例如 Scale)

转载 作者:IT老高 更新时间:2023-10-28 12:42:09 25 4
gpt4 key购买 nike

我希望使用 transform 为容器的比例设置动画。 AnimatedContainer 的属性(property);但是,比例尺并没有过渡,而是直接从头跳到尾。

代码片段:

var container = new AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: 50.0,
height: 50.0,
// selected is a bool that will be toggled
transform: selected ? new Matrix4.identity() : new Matrix4.identity().scaled(0.2,0.2),
decoration: new BoxDecoration(
shape: BoxShape.circle,
backgroundColor: Colors.blue[500],
),
child: new Center(
child: new Icon(
Icons.check,
color: Colors.white,
),
)
);

对正在发生的事情有任何见解吗?

最佳答案

AnimatedContainer 支持动画化它的变换值,如下:

/// scale to 95%, centerred
final width = 200.0;
final height = 300.0;
bool shouldScaleDown = true;// change value when needed
AnimatedContainer(
color: Colors.blueAccent,
width: width,
height: height,
duration: Duration(milliseconds: 100),
transform: (shouldScaleDown
? (Matrix4.identity()
..translate(0.025 * width, 0.025 * height)// translate towards right and down
..scale(0.95, 0.95))// scale with to 95% anchorred at topleft of the AnimatedContainer
: Matrix4.identity()),
child: Container(),
);

关于dart - 如何使用 AnimatedContainer 进行动画变换(例如 Scale),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42662936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com