Add on complete callback to SpriteAnimationWidget
Problem to solve
there is no easy way to know if an animation is finished when using it through SpriteAnimationWidget since it don't exposes a callback and internally it overrides any set callback on animation.onComplete
Proposal
Provide a callback on the widget constructor so the user can register the callback.
More information
I need to have a closer look but perhaps having a Controller would be closer to the ideal solution. Perhaps we can reuse the controller.
Another idea could be to expose the playing and listen when this value changes to false from true. Then, a setter for this could be used to, for example if we want the animation to be paused.
Anyways, this is just me naively dropping some ideas. I need to have a closer look at the actual code 👨💻
Hope it helps.
@alestiago I think it is important that it should be similar to the rest of our APIs, so passing in a callback I think would be the optimal solution. :)
@alestiago I think it is important that it should be similar to the rest of our APIs, so passing in a callback I think would be the optimal solution. :)
Forgot that this is the widget, I guess it should be as Fluttery as possible instead then.
I'll be soon raising a PR so that we can discuss how the API of this Widget should be from seeing some code.
@erickzanardo does https://github.com/flame-engine/flame/pull/1564 solve this issue?
@erickzanardo does #1564 solve this issue?
Humm, I think it offers an alternative, but a callback on the widget would be more straight forward and better for users.
Doesn't animation.completed.whenComplete(callback) allow using a callback?
Doesn't
animation.completed.whenComplete(callback)allow using a callback?
Yes, but that means that you need to hold an animation instance, which will probably require the use of a stateful widget.
SpriteAnimationWidget has some helper constructors that loads and manages the animation instance for you. So a callback received by the SpriteAnimationWidget would be the best.
We could even use the animation.completed internally to hook that callback that we would receive