Skip to content

[Feature Requested] Add useMultiTickerProvider Hook to Support Multiple tickers for one AnimationController #483

@Phenek

Description

@Phenek

Is your feature request related to a problem? Please describe.
When using flutter_map_animations with flutter_hooks, the AnimatedMapController requires a TickerProvider for its vsync parameter.
Currently, using the useSingleTickerProvider hook work at the first animation, but at the second animation the following error thorws:

attempted to use a useSingleTickerProvider multiple times.
A SingleTickerProviderStateMixin can only be used as a TickerProvider once.
If you need multiple Tickers, consider using useSingleTickerProvider multiple times
to create as many Tickers as needed.

In my use case, I cannot predict how many AnimationController instances will be created, so I need a useMultiTickerProvider hook to handle this dynamically.

Describe the solution you'd like
I would like a new hook, useMultiTickerProvider, that extends TickerProviderStateMixin instead of SingleTickerProviderStateMixin. This would allow the creation of multiple AnimationController instances without the limitation of a single TickerProvider. The hook should be usable like this:

AnimatedMapController useMapController(double initialZoom, Duration debounceDuration) {
  final ticker = useSingleTickerProvider();
  final controller = useMemoized(() => AnimatedMapController(vsync: ticker));

  useEffect(() {
    return () {
      try {
        controller.dispose();
      } catch (_) {}
    };
  }, const []);

  return controller;
}

Describe alternatives you've considered

  1. Using useSingleTickerProvider multiple times: This is not feasible because the number of required AnimationController instances is dynamic and unpredictable.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions