我想将列表中两个项目之间的间隙设置为动画.我想过使用高度最初为零的AminatedContainer,但我不熟悉如何实现这一点.我目前的代码是:

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

这确实改变了容器的高度,但并不像我希望的那样以一种生动的方式.任何帮助都将受到感激!

推荐答案

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

由于录音的原因, colored颜色 有点不合适,但你应该可以自己测试一下.

enter image description here

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;
                          })),
                ],
              )
            ],)
          ,)
    );
  }
}

Dart相关问答推荐

从GTIN中提取GS1公司前缀

当 ng-repeat 嵌套在 AngularDart 中时访问外部 $index

Flutter/Dart 为 Google Maps Marker 添加自定义点击事件

什么用例有 FirebaseUser 的 reload() 功能?

如何在 Flutter 中忽略整个文件的 lint 规则?

如何处理 ListView 滚动方向

Flutter:如何同步使用 SharedPreferences?

FInal和top-level lazy初始化

谷歌dart Regions?

无法导入 dart 的 intl 包

Expansion Panel底部溢出

单击 TextField 小部件时 Flutter 小部件重建

从Dart中的另一个文件导入扩展名方法

如何更改手机屏幕上的Flutter应用程序名称显示?

一个集合如何确定两个对象在dart中相等?

如何从 Dart 中的 forEach 循环返回?

从 Dart 应用访问 pubspec.yaml 属性

我应该更喜欢迭代 Map.entries 还是 Map.values?

在 Dart 中创建具有可变数量的参数或参数的函数

GWT 与 Dart - 主要区别是什么? Dart 是 GWT 的潜在替代品吗?