【问题标题】:How to make a widget animate based on child's size?如何根据孩子的大小制作小部件动画?
【发布时间】:2019-03-11 07:35:57
【问题描述】:

在 Flutter 中,AnimatedContainer 在您希望它根据孩子的大小制作动画时不起作用,它仅适用于其预定义的属性(如颜色、装饰、宽度、高度等...)。

当容器的孩子变大或变小时,或在其中接收更多小部件时,如何使容器的宽度/高度具有动画效果?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    使用AnimatedSize。每次它的孩子变大/变小或在其中接收更多孩子时,它都会动画。

    AnimatedSize(
      vsync: this,
      duration: Duration(milliseconds: 400),
      child: Column(
        children: <Widget>[
    
          SizedBox(
            width:  _box1Width,
            height:  _box1Height,
          ),
    
          SizedBox(
            width:  _box2Width,
            height:  _box2Height,
          ),
    
          SizedBox(
            width:  _box3Width,
            height:  _box3Height,
          ),
    
        ],
      ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-26
      • 2019-10-11
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 2011-01-28
      相关资源
      最近更新 更多