【问题标题】:How do I know that the transition animation is finish when push a new page推送新页面时如何知道过渡动画完成
【发布时间】:2019-12-04 03:53:14
【问题描述】:

推送新页面时,我会在 initState 中加载数据。这导致在过渡动画期间出现卡顿。这个问题在 Android 上尤为严重。

在 react native 中,我可以使用

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

flutter中有没有类似的方法。让我知道过渡动画完成了吗?

【问题讨论】:

标签: flutter


【解决方案1】:

在您的目标页面中,您可以获得ModalRoute 的实例。 ModalRoute 有一个 animation 属性公开 addStatusListener 以响应动画生命周期事件。

以下示例可能对您有所帮助:

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);
..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 2021-09-03
    相关资源
    最近更新 更多