我第一次尝试为Navigation.push实现自定义动画。这是我的代码:
onGenerateRoute: (routeSettings) {
return PageRouteBuilder<dynamic>(
settings: routeSettings,
pageBuilder: (context, Animation<double> animation,
Animation<double> secondaryAnimation) {
switch (routeSettings.name) {
case WelcomeScreen.id:
return WelcomeScreen();
case LoginScreen.id:
return LoginScreen();
case RegistrationScreen.id:
return RegistrationScreen();
case HomeScreen.id:
return HomeScreen();
default:
return null;
}
},
transitionDuration: Duration(milliseconds: 200),
transitionsBuilder: (context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
animation =
CurvedAnimation(curve: Curves.easeOut, parent: animation);
return SlideTransition(
position: Tween(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(animation),
child: child,
);
});
},
问题是,如果我将动画持续时间设置为例如。在此持续时间之后2秒钟,将执行“推入动画”,但不会出现“弹出动画”。如何确保我的流行动画的时长相同?
答案 0 :(得分:1)
您必须设置将要使用的reverseTransitionDuration
或弹出窗口