1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FlutterアプリでRIVE2製アニメーションが動かない!?場合に読む記事

Posted at

今回は、FlutterアプリのスプラッシュスクリーンにRIVE2を使ってアニメーションを作ってみました。
気づいたことや引っかかったことを簡単にまとめます。
大まかな流れなどは省いて、注意点のみ記載しています。

導入の仕方などは、こちらでOKだと思います。
https://zenn.dev/zumikou/scraps/8f9e1130af58e4
https://qiita.com/kitamuyu/items/13909a2888757b456837

RIVE2にjpg、pngファイルをインポートできない。

rive2
https://rive.app/index.html

自分の持っている画像を動かそうと思ったが無理でした。
しかし、svgファイルはうまくインポートできました。
自分で2Dの絵を作るところから始めるのがめんどくさい方は、svg素材を持っていると楽ですね。

packageのriveでアニメーションが動かない

以下がそのパッケージ
https://pub.dev/packages/rive

exampleからinitState部分を抜粋。

@override
  void initState() {
    super.initState();

    // Load the animation file from the bundle, note that you could also
    // download this. The RiveFile just expects a list of bytes.
    rootBundle.load('assets/off_road_car.riv').then(
      (data) async {
        final file = RiveFile();

        // Load the RiveFile from the binary data.
        if (file.import(data)) {
          // The artboard is the root of the animation and gets drawn in the
          // Rive widget.
          final artboard = file.mainArtboard;
          // Add a controller to play back a known animation on the main/default
          // artboard.We store a reference to it so we can toggle playback.
          artboard.addController(_controller = SimpleAnimation('idle'));
          setState(() => _riveArtboard = artboard);
        }
      },
    );
  }

僕は、rivファイルの部分のパスを自分のものに置き換えて終了かと思っていました。

しかし、

artboard.addController(_controller = SimpleAnimation('idle'));

'idle'の部分を自分で作ったアニメーションの名前に変更しないとダメでした。
僕の場合は以下の写真のように、名前は「Animation 1」でした。
スクリーンショット 2021-02-13 8.48.43.png
この2点がつまずいた点でした。
参考にならば幸いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?