-
-
Notifications
You must be signed in to change notification settings - Fork 191
Description
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
- Using
useSingleTickerProvidermultiple times: This is not feasible because the number of requiredAnimationControllerinstances is dynamic and unpredictable.