如何使用 AnimatedContainer 进行动画变换(例如缩放)

Dvd*_*ibi 10 dart flutter

我希望使用AnimatedContainertransform属性为容器的比例设置动画;然而,规模没有被过渡,直接从开始跳到结束。

代码片段:

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,
    ),
  )
);
Run Code Online (Sandbox Code Playgroud)

关于发生了什么的任何见解?

Ian*_*son 2

恐怕transform这是我们不设置动画的属性之一(child是另一个属性)。如果您想对比例进行动画处理,可以使用 ScaleTransition。

ScaleTransition:https://docs.flutter.io/flutter/widgets/ScaleTransition-class.html

Matrix lerp 的错误:https ://github.com/flutter/flutter/issues/443

  • 我假设您现在确实支持使用动画容器进行变换,因为它在您的本周小部件视频中如此说明:https://youtu.be/yI-8QHpGIP4?t=40 但不确定是如何完成的。 (3认同)