Open cachapa opened 6 years ago
Yeah, the problem is that on the first frame of the animation, the AnimationController starts at the initial values. Since you're updating every frame, you keep resetting it to the initial values.
I recommend creating your own SpringSimulation subclass that you can adjust the parameters on dynamically without restarting the animation controller.
We should probably give an example of doing this in the API docs somewhere. Maybe the Simulation class docs.
Maybe also mention in animateWith that calling it every frame will prevent the animation from advancing.
Android's SpringAnimation allows updating the target position in an existing object, which solves this issue.
I feel this is a common enough use case that it should be supported by SpringSimulation rather than forcing the developer to subclass it.
@Hixie I might be able to handle this. I'm trying to do something similar with springs. Do you have a sense for whether it's preferable to show a subclass doc example vs extend or introduce behavior as the previous commenter suggested?
Is there any progress now? I think a dynamically-updatable
animation is very important, it will guarantee to be continuous as well.
Animatable
Animatable is a value holder that automatically animates its value when the value is changed via animateTo. If animateTo is invoked during an ongoing value change animation, a new animation will transition Animatable from its current value (i.e. value at the point of interruption) to the new targetValue. This ensures that the value change is always continuous using animateTo. If a spring animation (e.g. default animation) is used with animateTo, the velocity change will guarantee to be continuous as well.There is a demo dynamic_animation
I'm trying to build a simple app which animates a red circle following the user's finger as it's dragged vertically on the screen. The problem I'm having is that the animation stops completely while the finger is dragged across the screen. As soon as dragging stops, the animation resumes normally.
I believe the problem is that there is no way to update the current SpringSimulation with a new target value, but rather I'm forced to create a new one on each "drag" event. This resets the internal simulation timer to zero, causing the movement to stop. From quick experimentation I couldn't get tween animations to work either, so I believe they have the same problem.
Source code
Flutter Doctor