颤动的secondaryAnimation没有运行

问题描述 投票:0回答:1

我正在使用以下代码将名为SecondPage的页面推送到堆栈中。使用animation的动画按预期运行。当SecondPage出现时,它会从屏幕底部向上滑动。

当我看着SecondPage时,我在ThirdPage上推了一个SecondPage。当我看到ThirdPage出现在屏幕上时,我没有看到SecondPage像我预期的那样根据下面的secondaryAnimation使用。事实上,在向SecondPage过渡期间根本没有ThirdPage的动画。 SecondPage在被ThirdPage覆盖时只是静止不动。

SecondPage出现时,如何让ThirdPage向上移动?

Navigator.push(
  context,
  PageRouteBuilder(
    pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
      return SecondPage();
    },
    transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
      return SlideTransition(
        position: Tween<Offset>(
          begin: const Offset(0.0, 1.0),
          end: Offset.zero,
        ).animate(animation),
        child: SlideTransition(
          position: Tween<Offset>(
            begin: Offset.zero,
            end: const Offset(0.0, -1.0),
          ).animate(secondaryAnimation),
          child: child,
        ),
      );
    },
  ),
);
flutter flutter-animation
1个回答
0
投票

SecondaryAnimation不会让你这样做。你应该使用Stack而不是让一个孩子成为其他孩子。

这就是你需要的。

transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  return Stack(
    children: [
      SlideTransition(
        position: Tween(begin: Offset(0, 1), end: Offset.zero).animate(animation),
        child: child,
      ),
      SlideTransition(
        position: Tween(begin: Offset.zero, end: Offset(0, -1)).animate(animation),
        child: this,
      ),
    ],
  );
},
© www.soinside.com 2019 - 2024. All rights reserved.