How do I know that the transition animation is finish when push a new page

677

In your destination page you can get an instance of ModalRoute. ModalRoute has an animation property exposing addStatusListener to react to animation lifecycle events.

The following exemple may help you :

Widget build(BuildContext context) {
    var route = ModalRoute.of(context);
    // Defining an internal function to be able to remove the listener
    void handler(status) {
      if (status == AnimationStatus.completed) {
        print('Animation completed !');
        route.animation.removeStatusListener(handler);
      }
    }
    route.animation.addStatusListener(handler);
..
Share:
677
Admin
Author by

Admin

Updated on December 15, 2022

Comments

  • Admin
    Admin 20 minutes

    When push a new page, I load the data in initState. This resulted in stuttering during the transition animation. This problem is particularly serious on Android.

    In react native, I can use

    InteractionManager.runAfterInteractions (() => {
               // ... do some time-consuming operations ...
    });
    

    Is there a similar method in flutter. Let me know that the transition animation is finish?