AnimatedContainer可以为其高度设置动画吗?

iBo*_*101 1 dart flutter

我想动画列表中两个项目之间的间隙.我想过使用AminatedContainer,其高度最初为零,但我不熟悉如何使其工作.我的代码目前是:

    new AnimatedContainer(
      duration: const Duration(milliseconds: 200),
      height: App.itemSelected==id ? 50.0 : 0.0,
      curve: Curves.fastOutSlowIn,
    ),
Run Code Online (Sandbox Code Playgroud)

这确实改变了容器的高度,但没有像我希望的那样以动画方式改变.感谢任何帮助!

azi*_*iza 5

我不确定是否AnimatedSize适合您的用例,但我添加了一个如何使用它制作简单动画的示例:

由于录音,着色有点偏,但你应该能够自己测试一下.

在此输入图像描述

class MyAppState extends State<MyApp> with TickerProviderStateMixin {
  double _height = 50.0;
  double _width = 20.0;
  var _color = Colors.blue;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new AnimatedSize(

                curve: Curves.fastOutSlowIn, child: new Container(
                width: _width,
                height: _height,
                color: _color,
              ), vsync: this, duration: new Duration(seconds: 2),),
              new Divider(height: 35.0,),
              new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new IconButton(
                      icon: new Icon(Icons.arrow_upward, color: Colors.green,),
                      onPressed: () =>
                          setState(() {
                            _color = Colors.green;
                            _height = 95.0;
                          })),
                  new IconButton(
                      icon: new Icon(Icons.arrow_forward, color: Colors.red,),
                      onPressed: () =>
                          setState(() {
                            _color = Colors.red;
                            _width = 45.0;
                          })),
                ],
              )
            ],)
          ,)
    );
  }
}
Run Code Online (Sandbox Code Playgroud)