flutter_hooks:启动和绑定到 AnimationController 的最简单的方式

问题描述

使用带有动画控制器的钩子。我想重建小部件,但不确定推荐的方式。文档或包本身中没有用于实际使用动画的示例。

我认为这是我们能做的最好的事情?有什么更好的方法吗?

final anim1 = useAnimationController(duration: Duration(seconds: 1));
useListenable(anim1);
final anim2 = useAnimationController(duration: Duration(seconds: 2));
useListenable(anim2);
useEffect(() {
  anim1.forward();
  anim2.forward();
  return null;
},[]);

注意:我希望构建整个小部件,而不是其中的一部分。我知道嵌套构建器可以做到这一点。

太糟糕了 useAnimation 没有内置对此的支持,所以这 9 行可以变成 2 行:

final anim1 = useAnimationController(autoPlay: true,buildWidget:  true,duration: Duration(seconds: 1));
final anim2 = useAnimationController(autoPlay: true,duration: Duration(seconds: 2));

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...