简体   繁体   English

使用 Flutter Visibility 小部件时,可见性的变化是否可以动画化?

[英]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.

相关问题 如何使用 Firebase 实时数据库和 FutureBuilder 更改 Flutter 小部件可见性? - How to change Flutter widget Visibility using Firebase Realtime Database and FutureBuilder? flutter 小部件中的可见性没有改变 - Visibility is not changing in a flutter widget 在 Flutter 中使用 Visibility Widget 来切换小部件的显示 - Using Visibility Widget in Flutter to toggle widgets display Flutter - 如何更改小部件列表中单个小部件的可见性? - Flutter - How to change the visibility of a single widget in a widget list? 单击其他元素时会触发可见性小部件颤动 - Visibility widget flutter triggers when other element clicked 在 Flutter 中切换可见性小部件时,如何避免移动到小部件下方? - How to avoid moving below widgets when Visibility widget is toggled in Flutter? 即使被另一个小部件覆盖,如何检查 Flutter 小部件的可见性 - How to check visibility of a Flutter widget even when covered by another 在 flutter 中可见性为真时强制滚动到小部件 - Force scroll to a widget when its visibility is true in flutter 使用 Flutter GetX 不切换可见性小部件内项目的显示 - Using Flutter GetX the display of the item inside the visibility widget is not toggled Flutter 在可见性小部件中维护表单的值 - Flutter maintain the values of a form in a visibility widget
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM