Skip to content

Need help in setting particular animation in new rive which was possible earlier #525

@nateshmbhat

Description

@nateshmbhat

In earlier versions of Rive , i used to do :

RiveAnimation.asset(
                  'lib/assets/myrivefile.riv',
                  stateMachines: ['State Machine 1'],
                  artboard: 'my artboard',
                  animations: ['swipe'],
                ),

In the newer "dev" version (0.14.x) , i'm able to get it to work but not able to set a specific animation. I searched through the code and docs, not seeming to find this option.

here's the code i have :

 @override
  Widget build(BuildContext context, WidgetRef ref) {
    final fileLoader = useMemoized(
        () => FileLoader.fromAsset(animation.assetPath, riveFactory: Factory.rive));
    useEffect(() => () => fileLoader.dispose(), []);

    return RiveWidgetBuilder(
        fileLoader: fileLoader,
        stateMachineSelector: animation.stateMachineName == null
            ? StateMachineSelector.byDefault()
            : StateMachineSelector.byName(animation.stateMachineName!),
        artboardSelector: animation.artboardName == null
            ? ArtboardSelector.byDefault()
            : ArtboardSelector.byName(animation.artboardName!),
        onLoaded: onLoaded,
        builder: (context, state) => switch (state) {
          RiveLoading() => const SizedBox.shrink(),
          RiveFailed() => const SizedBox.shrink(),
          RiveLoaded() => RiveWidget(
              controller: state.controller,
              fit: fit,
            )
        },
    );
  }

Can someone help me to set the animation like how i used to pass the animation list to the RiveAnimation.asset widget ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions