淡入/淡出FloatingActionButton?

时间:2019-12-03 14:34:02

标签: flutter dart

有什么方法可以慢慢淡入和淡出浮动动作按钮吗?我的列表中有一个FAB,可以为用户提供一种快速滚动到列表顶部的方法。

到目前为止,我已经在各种文章中找到了如何检测列表何时滚动到顶部或远离顶部(https://medium.com/@diegoveloper/flutter-lets-know-the-scrollcontroller-and-scrollnotification-652b2685a4ac)的方法,但是我找不到如何更改列表的alpha值的方法。小部件。知道如何解决这个问题吗?

谢谢 马丁

1 个答案:

答案 0 :(得分:1)

此示例来自flutter开发人员页面: 使用AnimatedOpacity,您可以淡化任何小部件。 只需将浮动动作按钮作为AnimatedOpacity的子项即可。 这是一些示例:

AnimatedOpacity(
  // If the widget is visible, animate to 0.0 (invisible).
  // If the widget is hidden, animate to 1.0 (fully visible).
  opacity: _visible ? 1.0 : 0.0,
  duration: Duration(milliseconds: 500),
  // The green box must be a child of the AnimatedOpacity widget.
  child: Container(
    width: 200.0,
    height: 200.0,
    color: Colors.green,
  ),
);

fade widget

您可以在此处找到更多信息和完整代码:https://flutter.dev/docs/cookbook/animation/opacity-animation