Flutter、Flare:在动画结束时执行函数

Flutter, Flare: Execute function on end of animation

我有一个简单的问题但找不到答案:有没有办法在我的 Flare 动画完成后执行一个函数?我有一个在应用程序启动时显示的动画,我希望在动画结束后显示主屏幕。我怎样才能做到这一点? 我尝试使用 Future.delayed() 但不知道将函数放在哪里。如果我将它放入 StartAnimation 小部件的构建器中,EnterExitRoute 将一遍又一遍地执行。

import 'package:flutter/material.dart';
import 'animations.dart';
import 'package:flare_flutter/flare_actor.dart';

String _animationName = "Start";

Center(
        child: GestureDetector(
          onTap: () {
            Navigator.push(context,
                EnterExitRoute(exitPage: this, enterPage: HomeScreen()));
          },
          child: Column(
            children: <Widget>[
              Center(
                child: Container(
                  height: 875,
                  child: FlareActor(
                    'src/animation.flr',
                    animation: _animationName,
                    fit: BoxFit.contain,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),

最终代码,有效:

import 'package:flutter/material.dart';
import 'animations.dart';
import 'package:flare_flutter/flare_actor.dart';

String _animationName = "Start";
bool _appStart = true;

[in build method]
  if (_appStart == true) {
              Navigator.push(context,
                EnterExitRoute(exitPage: this, enterPage: HomeScreen()));
              _appStart = false;
            }
[end of build method]

Center(
        child: Column(
          children: <Widget>[
            Center(
              child: Container(
                height: 875,
                child: FlareActor(
                  'src/animation.flr',
                  animation: _animationName,
                  fit: BoxFit.contain,
                ),
              ),
            ),
          ],
        ),
      ),

FlareActor 小部件有一个 callback 参数:

/// Callback invoked when [animation] has completed. If [animation] is looping
/// this callback is never invoked.
final FlareCompletedCallback callback;

另一种选择是使用 FlareControls 具有 method onCompleted(String name):

/// Listen for when the animation called [name] has completed.
void onCompleted(String name) {}

对于那些寻找回调的人

child: FlareActor(
    'src/animation.flr',
    animation: _animationName,
    fit: BoxFit.contain,
    callback: (animationName) {
        // Your code here. This is executed when the animation ends.
        // If the animation is looping, then it will never be called.
    },
),