I'm trying to show an animation from my riv flare. It was really simple in FlareActor and flr file. But can't show my animation with riv. I have 2 animations in my riv file. They are anim1 and anim2. I'm trying to show anim1 as default. Then trying to change it according to conditions. Here is my code snippet.
late RiveAnimationController? _controller;
Artboard? _riveArtboard;
@override
void initState() {
super.initState();
_loadRiveFile();
}
void _loadRiveFile() async {
await rootBundle.load('assets/animations/anim_file.riv').then(
(data) async {
final file = RiveFile.import(data);
final _artboard = file.mainArtboard;
_artboard.addController(_controller = SimpleAnimation('anim1'));
setState(() => _riveArtboard = _artboard);
},
);
}
This is build func:
GestureDetector(
onTap: () => {getStatus},
child: _riveArtboard == null ? const SizedBox.shrink(): Rive(artboard: _riveArtboard!))),
What I'm missing? Or how can I show my animation? Also I tried set controllers but it didn't work.
Rive provides
StateMachineControllerto switch between animations. If you wish to useSimpleAnimationyou can follow this way.To change between animation, you need to remove previous controllers and add the one you like to animate.
You can take a visit on this repository that follow this pattern.
I will encourage you to use
StateMachineControllerIn this case, you need some sort of input value while implementing animation on rive.
On dart level,
All you need to provide
isAnim1.value= falsebased on your scenario, and it will switch the animation.Check this question on Stackoverflow and GitHub repository .