gpt4 book ai didi

flutter - SliverAppBar 中的动画 => 动态调整栏的大小

转载 作者:行者123 更新时间:2023-12-03 13:30:03 27 4
gpt4 key购买 nike

我收到了 SliverAppBarAnimatedContainer里面。此动画容器的高度在运行时会发生变化,因此容器会对其大小进行动画处理。我的问题是,expandedHeight我的 SliverAppBar 已修复。但这需要调整模拟我的动画容器的大小。
有没有办法将 SliverAppBar 设置为“高度总是根据 child ”或类似的东西? AnimatedContainer 没有回调,它在为调整大小设置动画时为我提供了所有更改。如果有这样的回调,我可以更改 expandedHeight SliverAppBar 的属性由我自己决定。
知道如何解决我的问题吗?谢谢!

return SliverAppBar(
elevation: 0,
snap: true,
pinned: false,
floating: true,
forceElevated: false,
primary: false,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
expandedHeight: _eHeight,
flexibleSpace: Column(children: <Widget>[
AnimatedContainer(
onEnd: onTopBarsAnimationEnd,
height: _trending
? _tabBarHeight: _tabBarHeight + topicsHeight,
duration: Duration(milliseconds: 800),
curve: Curves.fastOutSlowIn,
child: // some child
)
]
)
)

编辑 - 这是一个 gif 显示我想要实现的目标:
enter image description here

最佳答案

如果您检查 AnimatedContainer docs , 他们说:

This class is useful for generating simple implicit transitions between different parameters to Container with its internal AnimationController. For more complex animations, you'll likely want to use a subclass of AnimatedWidget such as the DecoratedBoxTransition or use your own AnimationController.


在这里,“隐式”意味着您将无法控制动画,因此您将无法访问 AnimationController允许您收听动画步骤的类。要做到这一点,你需要像 AnimatedWidget 这样的东西。 .
深入研究 AnimationController 会发现它继承自 ImplicitlyAnimatedWidget,文档说:

ImplicitlyAnimatedWidgets (and their subclasses) automatically animate changes in their properties whenever they change. For this, they create and manage their own internal AnimationControllers to power the animation. While these widgets are simple to use and don't require you to manually manage the lifecycle of an AnimationController, they are also somewhat limited: Besides the target value for the animated property, developers can only chose a duration and curve for the animation. If you require more control over the animation (e.g. you want to stop it somewhere in the middle), consider using a AnimatedWidget or one of its subclasses. These widget take an Animation as an argument to power the animation. This gives the developer full control over the animation at the cost of requiring you to manually manage the underlying AnimationController.


所以你需要的是创建你的 AnimatedController 对象并将它传递给一个 AnimatedWidget。您可以在 docs 中看到一个示例。 .
最后,要在每个动画步骤中执行某些操作,您需要使用其方法 向 AnimatedController 添加一个监听器函数。 addListener ,通常在小部件的 initState 方法中完成的操作。

关于flutter - SliverAppBar 中的动画 => 动态调整栏的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62532971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com