[英]When using Flutter Visibility widget, can the change in visibility be animated?
I have a column holding a number of containers.我有一个包含许多容器的列。 The top and bottom containers are always shown, but the ones between sit inside a Visibility widget.始终显示顶部和底部容器,但介于两者之间的容器位于 Visibility 小部件中。 If the user taps the screen, the middle containers are made visible, and then are made invisible again on the next tap.如果用户点击屏幕,中间的容器会变得可见,然后在下次点击时再次变为不可见。 So essentially, the column expands and contracts each time it's tapped.所以本质上,柱子每次被点击时都会膨胀和收缩。
I'd like the expansion and contraction to happen a bit more gracefully - currently it looks very harsh when the middle containers just suddenly appear.我希望膨胀和收缩能够更优雅地发生 - 目前当中间容器突然出现时看起来非常刺耳。 Is there any way of animating the way in which the containers are made visible and hidden?有什么方法可以动画化容器可见和隐藏的方式吗? Or should I be looking at using a totally different Widget than Visibility?还是我应该考虑使用与可见性完全不同的小部件?
You can use an animated crossfade.您可以使用动画交叉渐变。 Make the first child as SizedBox.shrink() and second child as the widget that you wish to display and it should be animating as expected.将第一个孩子设置为 SizedBox.shrink() 并将第二个孩子设置为您希望显示的小部件,它应该按预期进行动画处理。 And switch according to the requirement并根据要求切换
bool _first = true;
AnimatedCrossFade(
duration: const Duration(seconds: 1),
firstChild: const SizedBox.shrink(),
secondChild: const FlutterLogo(style: FlutterLogoStyle.stacked, size: 100.0),
crossFadeState: _first ? CrossFadeState.showFirst : CrossFadeState.showSecond,
)
Alter the value of _first to true or false.将 _first 的值更改为 true 或 false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.