最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

FlutterRive, State Machine. Animation works fine, event never triggers - Stack Overflow

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论