flutter disable animation router navigator.pushNamed

Viewed 343

I use a router for my app. and use Navigator.pushNamed for use it. but I don't want an animation for it.

MaterialApp(
debugShowCheckedModeBanner: false,
 routes: routes,
 initialRoute: '/firstPage')

here is my routes :

Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
  '/firstPage': (context) => const FirstPage(),
  '/': (context) => const BottomNavBar( activeTabIndex: 0, widgetActive: ExploreHome(), ),

   // another routes
  };

and I use this for call routes :

 Navigator.pushNamed(
    context,
    '/',
    arguments: {
    "title": "explore",
    "text": "something"
     },);

and use final args = (ModalRoute.of(context)!.settings.arguments ??{"title": " ", "text": ""}) as dynamic; to get argument for my ExploreHome() class.

so how can I remove the animation router?

1 Answers

You need to use onGenerateRoute in your MaterialApp widget.

onGenerateRoute: (settings) {
  if (settings.name == "/initialRoute") {
    return PageRouteBuilder(
      transitionDuration: Duration.zero,
      settings: settings,
      pageBuilder: (_, __, ___) => InitialPage(),
  }
  // default route
  return PageRouteBuilder(
         transitionDuration: Duration.zero,
         settings: settings,
         pageBuilder: (_, __, ___) => DefaultRoute(),
  },
Related