Minhajul Islam Zahin
Minhajul Islam Zahin

Reputation: 13

How do I call the inputs of nested artboard 'mouth' used in my main artboard in flutter?

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

Answers (1)

Zihan
Zihan

Reputation: 962

rive editor image

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

rive doc link

Upvotes: 0

Related Questions