Reputation: 13
I'm using Rive in my Flutter app for animations. I have a main artboard with a nested artboard called "mouth." I want to access the inputs (hear and sad) from both artboards, but I'm having trouble with the nested artboard's inputs.
Here’s my code:
RiveAnimation.asset(
RiveAsset.RG,
artboard: 'Artboard',
fit: BoxFit.contain,
onInit: onRiveInit,
);
SMIInput<bool>? hearInput;
SMIInput<bool>? sadInput;
void onRiveInit(Artboard artboard) {
final controller = StateMachineController.fromArtboard(
artboard,
'main',
);
if (controller != null) {
artboard.addController(controller);
hearInput = controller.findInput<bool>('hear'); // Input from the main artboard
sadInput = controller.findInput<bool>('sad'); // Input from the nested artboard
}
}
The issue is that while hearInput (from the main artboard) works correctly, sadInput (from the nested artboard) does not work with the findInput method. How can I access inputs from a nested artboard in Rive?
Upvotes: 1
Views: 42
Reputation: 962
First you need to make sure that, You have downloaded the riv file with export name selected like the picture
then you can use it like below
void onRiveInit(Artboard artboard) {
final StateMachineController? controller =
StateMachineController.fromArtboard(
artboard,
'main',
);
if (controller != null) {
artboard.addController(controller);
// Main working
hearInput = controller.findInput<bool>('hear');
}
sadInput = artboard.getBoolInput('sad', 'mouth');
}
you can also get the documentation from here
Upvotes: 0