useAnimationController function

AnimationController useAnimationController({
  1. Duration? duration,
  2. Duration? reverseDuration,
  3. double? initialValue,
  4. double lowerBound = 0,
  5. double upperBound = 1,
  6. TickerProvider? vsync,
  7. List<Object?>? keys,
})

An AnimationController made by the first build, made anew when the keys of a build differ from the last one's, and disposed with the element or when replaced. Its ticker is the hook's own, ticking in the frames of the app the widget is in, unless vsync gives one. That ticker is muted (Ticker.muted) while a TickerMode above is off, so that the controller stands still and asks for no frame, and goes on when it is on again, its time having gone on meanwhile: it is where it would have been. A vsync is muted by its own owner.

Each build sets the controller's duration and reverseDuration; initialValue, the bounds and vsync are those of the build that made it.

A bar that grows over a second from the first build:

HookBuilder(
  builder: (context) {
    final controller = useAnimationController(
      duration: const Duration(seconds: 1),
    );
    useEffect(() {
      controller.forward();
      return null;
    }, const []);
    final value = useListenable(controller).value;
    return Text('█' * (value * 20).round());
  },
)

Implementation

AnimationController useAnimationController({
  Duration? duration,
  Duration? reverseDuration,
  double? initialValue,
  double lowerBound = 0,
  double upperBound = 1,
  TickerProvider? vsync,
  List<Object?>? keys,
}) => use(
  _AnimationControllerHook(
    duration: duration,
    reverseDuration: reverseDuration,
    initialValue: initialValue,
    lowerBound: lowerBound,
    upperBound: upperBound,
    vsync: vsync,
    keys: keys,
  ),
);