kalismeras61 / flutter_page_transition

This is Flutter Page Transition Package
BSD 2-Clause "Simplified" License
475 stars 57 forks source link

not working when using Navigator. pushNamed with arguments #21

Closed jpainam closed 4 years ago

jpainam commented 4 years ago

Hi, The argument passed to Navigator.of(context) .pushNamed(SecondScreen.routeName, arguments: AnObject) is always null when SecondScreen route is registered as

 onGenerateRoute: (settings){
          switch(settings.name){
              case SecondScreen.routeName:
                return PageTransition(child: SecondScreen(), type: PageTransitionType.downToUp);
                break;
            default:
              return null;
          }

AnObject is always null in SecondScreen. But when the route is registered as

routes: {
          '/': (context) => HomeScreen(),
          SecondScreen.routeName: (context) => SecondScreen(),
        },

the argument is retrieved. How to use PageTransition plugin with namedroute and arguments?

Thank,

kalismeras61 commented 4 years ago

Hi, The argument passed to Navigator.of(context) .pushNamed(SecondScreen.routeName, arguments: AnObject) is always null when SecondScreen route is registered as

 onGenerateRoute: (settings){
          switch(settings.name){
              case SecondScreen.routeName:
                return PageTransition(child: SecondScreen(), type: PageTransitionType.downToUp);
                break;
            default:
              return null;
          }

AnObject is always null in SecondScreen. But when the route is registered as

routes: {
          '/': (context) => HomeScreen(),
          SecondScreen.routeName: (context) => SecondScreen(),
        },

the argument is retrieved. How to use PageTransition plugin with namedroute and arguments?

Thank,

Sorry for delay. did you read readme.md file? I think it is very well explained how to use arguments.

First you need to upgrade your package with latest package. Than Usage predefined routes with RouteSettings First, define the onGenerateRoute property in the MaterialApp widget like below and in switch cases you can transition to your new routes:

   onGenerateRoute: (settings) {
        switch (settings.name) {
          case '/second':
            return PageTransition(
              child: SecondPage(),
              type: PageTransitionType.scale,
              settings: settings,
            );
            break;
          default:
            return null;
        }
      },
After that you can use your new route like this:

Navigator.pushNamed(context, '/second', arguments: "arguments data");
kalismeras61 commented 4 years ago

Due inactivity i will go close this. If you have any issue please reopen again.