Skip to main content

useSingleTickerProvider

Provides a single TickerProvider for the current hook context, the hook equivalent of SingleTickerProviderStateMixin. It supplies the vsync an animation controller needs.

class BlinkingDot extends HookWidget {
const BlinkingDot({super.key});


Widget build(BuildContext context) {
final TickerProvider vsync = useSingleTickerProvider(); // <- One ticker for this widget

// Drive the controller with the hook-provided vsync instead of a State mixin.
final controller = useAnimationController(vsync: vsync, duration: const Duration(seconds: 1));

useEffect(() {
controller.repeat(reverse: true);
return null;
}, const []);

return FadeTransition(opacity: controller, child: const Icon(Icons.circle, size: 16));
}
}

Signature

TickerProvider useSingleTickerProvider();

Returns a TickerProvider that creates exactly one Ticker. The provider tracks the ambient TickerMode, so its ticker is muted automatically when an enclosing TickerMode is disabled (for example, an off-screen route).

Use cases

  • Supplying vsync to an AnimationController you build yourself, or to any Flutter API that asks for a TickerProvider.
  • Most code never needs this hook directly: useAnimationController calls it internally when you omit vsync. Reach for it explicitly only when you construct a controller (or another ticker consumer) by hand.

Caveats

  • It is a single ticker provider, mirroring SingleTickerProviderStateMixin. Asking it for a second ticker is unsupported - one provider backs one controller. For multiple controllers in one widget, give each its own useSingleTickerProvider, or supply a multi-ticker provider from elsewhere.
  • The returned provider is tied to this hook context's lifecycle; don't store it past the build and reuse it from an unrelated widget.

See also