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 callback persisting unwanted state #276

Open alirezava opened 4 years ago

alirezava commented 4 years ago

Hi,

New to flare and flutter so I might be using it wrong. But what I'm trying to do is create a simple Stateless widget that renders a background with a flare animation with a callback on completing animation. However, once the callback is set it will get called even when instantiated with a new callback (or null).

class LoginHeader extends StatelessWidget {
  final Function callback;
  final String animation;
  LoginHeader(this.callback, this.animation);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) => Container(
        height: constraints.maxHeight,
        width: constraints.maxWidth,
        child: FlareActor(
          "assets/flare/LoginBackground.flr",
          alignment: Alignment.topCenter,
          fit: BoxFit.fill,
          animation: animation,
          callback: this.callback,
        ),
      ),
    );
  }
}

And from a stateful widget I'm instantiating it like so

LoginHeader(loggedIn ? doSomethingElse : showLoginCard, animation)

The animation parameter does what's expected when called with a new animation string, but some reason the callback still references the previous one even if loggedIn is true. It completely ignored my doSomethingElse callback and invokes showLoginCard.

Any help would be really appreciated.

ghost commented 3 years ago

Having similar issues. Here's my issue (if it helps): https://github.com/2d-inc/Flare-Flutter/issues/284#issue-728970538