【发布时间】:2018-09-05 14:38:17
【问题描述】:
我有一个 ListTile 列表,每当我点击它们时,都会出现一个新页面。目前,新页面将向上滑动(出现时)和向下滑动(移除时)。我想将过渡动画更改为 Fade。
我已经阅读了here 中的解决方案,然后我编辑了链接中的代码,结果如下。
class MyCustomRoute<T> extends MaterialPageRoute<T> {
MyCustomRoute({ WidgetBuilder builder})
: super(builder: builder);
@override
Widget buildTransitions(BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child) {
if (settings.isInitialRoute)
return child;
return new FadeTransition(opacity: animation, child: child);
}
}
与我的链接解决方案的唯一区别是我从未将“设置”变量提供给 MaterialPageRoute 类。
这是我使用 Navigator.push 的代码部分:
new ListTile(
onTap: (){
Navigator.push(context, new MyCustomRoute(builder: (context) => new SecondPage("someTitle", "someDescription") ));
},
//The rest of the code goes here
我尝试运行此代码,但我从未想过它会顺利运行,因为我从未向 MaterialPageRoute 小部件提供设置变量,但它运行完美。
我的问题是,这是正确的做法吗?要么 我应该为 MaterialPageRoute 类提供设置吗? 而且由于我没有为 MaterialPageRoute 类提供设置变量,它的设置是从哪里获得的?在这部分代码中:
if (settings.isInitialRoute)
return child;
我将不胜感激。提前致谢。
【问题讨论】: