2d-inc / Flare-Flutter

Load and get full control of your Rive files in a Flutter project using this library.
https://rive.app/
MIT License
2.55k stars 469 forks source link

FlareActor holds incorrect callback references #284

Closed ghost closed 3 years ago

ghost commented 3 years ago

Within my app, I'm calling the same FlareActor twice (through a private stateless widget) but with different callback functions. The first callback calls a null (it loops a loading animation so it's not going use the callback either way) and the second time it's a function that notifies that the 'done' animation is complete.

I've modified my code to provide some helpful print statements (including changing the parent).

Stateless Widget (with FlareActor) ```dart class _Splash extends StatelessWidget { const _Splash({Key key, this.isLoading = true, this.onComplete}) : super(key: key); final bool isLoading; final Function onComplete; @override Widget build(BuildContext context) { print('Flutter: $onComplete'); return Center( child: SizedBox( height: 250, child: FlareActor( "lib/graphics/splash-screen.flr", alignment: const Alignment(0, 0), fit: BoxFit.contain, animation: isLoading ? 'loading' : 'done', callback: (_) { print('FlareActor: $onComplete'); }, ), ), ); } } ```
Parent Widget (Important bits only) ```dart if (state is SplashScreenLoading) { return _Splash(onComplete: () => 'stringType'); } if (state is SplashScreenSuccess) { return _Splash(isLoading: false, onComplete: () => cubit.animationEnded()); } ```

So I expect the FlareActor to call the new function, but that's not what happens.

Print Statements ``` I/flutter ( 3231): Flutter: Closure: () => String I/flutter ( 3231): Flutter: Closure: () => void I/flutter ( 3231): FlareActor: Closure: () => String ```

Notice how flutter (and thus the widget) has the reference to the new function (which goes to void) but FlareActor is calling the old function? Am I doing something wrong or is this not intended?

ghost commented 3 years ago

Duplicate of #276