rive-app / rive-flutter

Flutter runtime for Rive
https://rive.app
MIT License
1.21k stars 191 forks source link

If animationName changed from 'Untitled 1' to anything else - no playback. #36

Closed Floul closed 3 years ago

Floul commented 3 years ago

If I change a name of the animation in an animation controller - animation doesn't play. If I set it back to 'Untitled 1' - animation performs as expected.

class CircularLoadingIndicator extends StatefulWidget {
  const CircularLoadingIndicator({
    Key key,
  }) : super(key: key);

  @override
  _CircularLoadingIndicatorState createState() => _CircularLoadingIndicatorState();
}

class _CircularLoadingIndicatorState extends State<CircularLoadingIndicator> with SingleTickerProviderStateMixin {
  Artboard _riveArtboard;
  RiveAnimationController _controller;

  @override
  void initState() {
    rootBundle.load(RiveElements.circularLoadingIndicator).then(
      (data) async {
        final file = RiveFile();

        if (file.import(data)) {
          final artBoard = file.mainArtboard
            ..addController(
              _controller = SimpleAnimation('Spinning')..isActive = true,  //works only if 'Untitled 1'
            );
          setState(() => _riveArtboard = artBoard);
        }
      },
    );
    super.initState();
  }

  @override
  Widget build(BuildContext context) => SizedBox(
        width: 44,
        height: 44,
        child: Rive(
          artboard: _riveArtboard,
        ),
      );

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }
}
mjohnsullivan commented 3 years ago

The animation name must match an animation present in the artboard and Rive file; does the file you're loading have animations with 'spinning' in the main artboard?

mjohnsullivan commented 3 years ago

Can you share a Rive file that's causing the problem? Happy to take a look at it.

mjohnsullivan commented 3 years ago

I'll close this for the moment, but please feel free to reach out if you're still having problems and we can assist.