admin管理员组

文章数量:1399313

Trying to test rive animations in flutter and use changable data based on rive triggers.

The rive file is a simple click animation and works fine but the event 'onRiveEvent' never fires so I can't make changes in data.

expected results: prints in Debug Console.

Gif with example

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // SMIInput<bool>? _booleanInput;
  void onRiveEvent(RiveEvent event) {
    print('sdasda');
    print(event);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RiveAnimation.asset('assets/test2.riv',
            onInit: (Artboard artboard) {
          final controller =
              StateMachineController.fromArtboard(artboard, 'State Machine 1');
          controller!.addEventListener(onRiveEvent);
          artboard.addController(controller);
          // _booleanInput = controller.findInput<bool>('on');
        }),
      ),
    );
  }
}

Trying to test rive animations in flutter and use changable data based on rive triggers.

The rive file is a simple click animation and works fine but the event 'onRiveEvent' never fires so I can't make changes in data.

expected results: prints in Debug Console.

Gif with example

import 'package:flutter/material.dart';
import 'package:rive/rive.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // SMIInput<bool>? _booleanInput;
  void onRiveEvent(RiveEvent event) {
    print('sdasda');
    print(event);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RiveAnimation.asset('assets/test2.riv',
            onInit: (Artboard artboard) {
          final controller =
              StateMachineController.fromArtboard(artboard, 'State Machine 1');
          controller!.addEventListener(onRiveEvent);
          artboard.addController(controller);
          // _booleanInput = controller.findInput<bool>('on');
        }),
      ),
    );
  }
}
Share Improve this question asked Mar 25 at 13:44 Richard WinterRichard Winter 31 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In Rive App we should explicitly emit events in order to view it in runtime. There are actually elements (next to joysticks) called 'event' that triggers due to conditions in State Machine logic.

本文标签: FlutterRiveState Machine Animation works fineevent never triggersStack Overflow