如何在没有动画 Flutter 的情况下导航到其他页面

问题描述:

我有一个登录页面,当我登录到我正在使用的应用程序的主页时Navigator.pushReplacement(context, new MaterialPageRoute(builder: (BuildContext context) => new Page1()));但是它有幻灯片动画,我想禁用它.

I have a Login page, when I log on to go to the main page of my app i am using Navigator.pushReplacement(context, new MaterialPageRoute(builder: (BuildContext context) => new Page1())); But it have the slide animation, i want to disable it.

这是我的 Material 应用格式

this is my Material app format

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new Login(title: 'Login'),
      routes: <String, WidgetBuilder>{
        '/screen3': (BuildContext context) => new Page1(),
      },
    );
  }
}

您可以使用 PageRouteBuilder.

Navigator.pushReplacement(
    context, 
    PageRouteBuilder(
        pageBuilder: (context, animation1, animation2) => Page1(),
        transitionDuration: Duration.zero,
    ),
);