Open workerbee22 opened 4 years ago
The callback registered within FlareActor
is used on the animations that are played through FlareActor
only.
Since you're playing animations with your SpeedController
, you should add a callback parameter to that as well:
class SpeedController extends FlareController {
[...]
FlareCompletedCallback onAnimationCompleted;
// Optional param spped defaults to 1 if not provided
SpeedController(this.animationName, {this.speed = 1, this.onAnimationCompleted});
@override
bool advance(FlutterActorArtboard artboard, double elapsed) {
if (_animation == null) {
return false;
}
if (_animation.isLooping) {
_time %= _animation.duration;
}
_animation.apply(_time, artboard, 1.0);
_time += elapsed * speed;
if (_time > _animation.duration && onAnimationCompleted != null) {
onAnimationCompleted(_animation.name);
}
// Stop advancing if animation is done and we're not looping.
return _animation.isLooping || _time < _animation.duration;
}
[...]
}
Thanks @umberto-sonnino but is there any documentation on how FlareCompletedCallback works? Changes above crash when onAnimationCompleted(_animation.name);
is executed.
FlareCompletedCallback
is just a type definition:
typedef void FlareCompletedCallback(String name);
It is a function that takes a String parameter and doesn't return any value.
In the snippet above, you need to specify a callback in the constructor for it to not crash. I'll update it with a null check!
And when instantiating your SpeedController
:
SpeedController(
myAnimationName,
onAnimationCompleted: (name) {
print("Animation $name completed!");
}
)
Continuing to try and get a basic countdown going. Sample code uses the flare speed control example https://github.com/luigi-rosso/flare_control_speed_example/blob/master/lib/main.dart
Using flare_flutter 1.7.3
This code never prints"finished":