Search code examples
flutterflare

Flutter, Flare: Execute function on end of animation


I have a simple question but can't find an answer to it: Is there a way to execute a function after my Flare animation is finished? I have an animation that is shown on the app launch and I want the home screen to be shown after the animation is over. How can I do this? I tried using Future.delayed() but don't know where to put the function. If I put it into the builder of the StartAnimation widget, the EnterExitRoute is executed over and over again.

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,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),

Solution

  • The final code, working:

    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,
                    ),
                  ),
                ),
              ],
            ),
          ),