我正在使用以下代码将名为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,
),
);
},
),
);
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,
),
],
);
},