颤动上的 Rive 动画不起作用并且是静态的

时间:2021-05-10 05:41:38

标签: flutter rive

我是 flutter 的新手,对此一无所知,我从 rive 应用程序创建了一个简单的设计,并尝试在 flutter 应用程序上运行,但动画没有运行。我从 flutter 下载的动画作品很少有工作,有些没有工作,链接上的下面的一个也没有工作。它只是静态的 png 图像。我尝试将动画名称更改为空闲或居中,但仍然无效。

这是rive download link.

这是我正在使用的代码,

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

class ExampleAnimation extends StatefulWidget {
  const ExampleAnimation({Key? key}) : super(key: key);

  @override
  _ExampleAnimationState createState() => _ExampleAnimationState();
}

class _ExampleAnimationState extends State<ExampleAnimation> {
  void _togglePlay() {
    if (_controller == null) {
      return;
    }
    setState(() => _controller!.isActive = !_controller!.isActive);
  }

  bool get isPlaying => _controller?.isActive ?? false;

  Artboard? _riveArtboard;
  RiveAnimationController? _controller;
  @override
  void initState() {
    super.initState();
    rootBundle.load('assets/rive/new.riv').then(
      (data) async {
        // Load the RiveFile from the binary data.
        final file = RiveFile.import(data);
        final artboard = file.mainArtboard;
        // ignore: cascade_invocations
        artboard.addController(_controller = SimpleAnimation('animate'));
        setState(() => _riveArtboard = artboard);
         
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Animation Example'),
      ),
      body: Center(
        child: _riveArtboard == null
            ? const SizedBox()
            : Rive(artboard: _riveArtboard!),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _togglePlay,
        tooltip: isPlaying ? 'Pause' : 'Play',
        child: Icon(
          isPlaying ? Icons.pause : Icons.play_arrow,
        ),
      ),
    );
  }
}

2 个答案:

答案 0 :(得分:1)

我刚刚遇到了同样的问题,在之前的回答中,他提到更改为他工作的动画控制器的名称,不幸的是,我不知道该动画控制器的值在哪里被选取以及它是什么,所以只是想要澄清一下。

在您的 Rive 画板中,会有一个名为 animations 的列,您必须将该名称指定给您的动画控制器,以选择应播放的动画。

Click here to know what the animation controller is

答案 1 :(得分:0)

动画名称不正确,在这一行我只需要更改应用程序上的动画名称。

=SUMIFS(B:B,C:C,"Deposit",D:D,"Robinhood")

对于我来说,动画名称只是动画 1。所以添加它解决了我的问题。