请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

growTransition没有动画效果

构造GrowTransition部分的代码如下:

class TransitionGroup extends StatelessWidget {
  TransitionGroup({this.child, this.animation});
  final Widget child;
  final Animation<double> animation;

  
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: animation,
      builder: (context, child) => Container(
            height: animation.value,
            width: animation.value,
            child: child,
          ),
      child: child,
    );
  }
}

其他都没怎么变动,但是没有动画效果,调用部分代码:


  Widget build(BuildContext context) {
    return TransitionGroup(
      animation: animation,
      child: LogoWidget(controller: controller),
    );
  }

其中LogoWidget中传入controller是为了点击图片能重置动画,对效果应该不影响,所以核心问题感觉应该是出在GrowTransition上。

正在回答 回答被采纳积分+3

1回答

提问者 晓晓晓晓丶vv 2019-03-25 15:05:37

找到原因了,`AnimatedBuilder`需要包裹在`Center`中才有效果,这是为什么?我把`Center`改成`Container`也不行,是不是只能在`Center`中?

1 回复 有任何疑惑可以回复我~
  • AnimatedBuilder需要布局约束才能显示,方便使用可以放到Center中,但不是必须的
    回复 有任何疑惑可以回复我~ 2019-03-26 22:40:14
  • 提问者 晓晓晓晓丶vv 回复 CrazyCodeBoy #2
    约束条件我可以理解成 需要一个容器裹着它吗? 然后不理解的就是 为什么有的容器能有约束左右 有的容器却没有
    回复 有任何疑惑可以回复我~ 2019-03-27 14:29:03
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信