How to remove default navigation route animation
Replace your MyApp
with this.
class MyApp extends StatelessWidget {
final routes = <String, WidgetBuilder>{SecondRoute.tag: (context) => SecondRoute()};
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Routes",
home: new FirstRoute(),
onGenerateRoute: (routeSettings) {
if (routeSettings.name == SecondRoute.tag)
return PageRouteBuilder(
pageBuilder: (_, a1, a2) => FadeTransition(opacity: a1 ,child: SecondRoute()),
transitionDuration: Duration(seconds: 5),
);
return null;
},
);
}
}
For
Navigator.push(...)
Navigator.push( context, PageRouteBuilder(pageBuilder: (_, __, ___) => SecondRoute()), )
For
Navigator.pushNamed(...)
First, add this to your
MaterialApp
MaterialApp( onGenerateRoute: (settings) { if (settings.name == '/second') return PageRouteBuilder(pageBuilder: (_, __, ___) => SecondRoute()); return null; }, )
And now, you can use:
Navigator.pushNamed(context, '/second');
The animation is performed by MaterialPageRoute
. If you don't want it, simple use something else:
Navigator.push(
context,
PageRouteBuilder(pageBuilder: (_, __, ___) => MyRoute()),
)