0

我有一个简单的问题,但找不到答案:有没有办法在我的 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,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
4

3 回答 3

1

FlareActor部件有一个回调参数:

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

其他替代方法是使用FlareControls具有方法 onCompleted(String name)的 a :

/// Listen for when the animation called [name] has completed.
void onCompleted(String name) {}
于 2020-07-09T22:18:43.467 回答
0

对于那些寻找回调的人

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.
    },
),
于 2021-06-14T17:03:03.863 回答
-2

最终代码,工作:

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,
                ),
              ),
            ),
          ],
        ),
      ),
于 2020-05-27T22:41:39.860 回答