Flutter useAnimationController 钩子不重建小部件

Flutter useAnimationController hook doesn't rebuild widget

我正在使用 flutter hooks 包来为屏幕上的元素设置动画,但显然我做错了什么,因为元素没有重建为动画。这是我的代码。

class Ball extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final xController = useAnimationController(
      duration: Duration(seconds: 3),
      lowerBound: 0,
      upperBound: 2,
      initialValue: 1,
    );

    final yController = useAnimationController(
      duration: Duration(seconds: 3),
      lowerBound: 0,
      upperBound: 2,
      initialValue: 1,
    );

    useEffect(() {
      xController.repeat(reverse: true);
      yController.repeat(reverse: true);

      return () {};
    });

    return Align(
      alignment: Alignment(
        xController.value - 1,
        yController.value - 1,
      ),
      child: Container(
        width: 12,
        height: 12,
        decoration: BoxDecoration(
          color: Colors.grey[900],
          shape: BoxShape.circle,
        ),
      ),
    );
  }
}

呈现时,此小部件位于堆栈内。在运行时或构建时都不会抛出任何错误。

对于以后看到此内容的任何人,您都必须这样做

final xController = useAnimationController({ ... })
useAnimation(xController)