kalismeras61 / flutter_page_transition

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

Navigator.pushNamed doesn't work. #74

Closed maulaniad closed 1 year ago

maulaniad commented 1 year ago

While using the Navigator.push(context, PageTransition(child: Widget(),),),. it does work . but when using onGenerateRoutes, routes, and pushNamed it doesn't,

here's my code :

routes: {
  '/': (context) => const LaunchPage(),
  '/landing': (context) => const LandingPage(),
  '/login': (context) => const LoginPage(),
},
onGenerateRoute: (routeSettings) {
  switch (routeSettings.name) {
    case '/landing':
      return PageTransition(
        settings: routeSettings,
        type: PageTransitionType.topToBottomPop,
        child: const LandingPage(),
      );
    break;
    case '/login':
      return PageTransition(
        settings: routeSettings,
        type: PageTransitionType.fade,
        child: const LandingPage(),
      );
    break;
    default:
      return null;
  }
},

here's how i called it : Navigator.pushNamed(context, '/landing');

However it just plays the default transition with no effect.

Here's my project tree in case it's needed :

lib/
├─ screens/
│  ├─ launch_page.dart
│  ├─ landing_page.dart
│  ├─ login_page.dart
├─ main.dart

MaterialApp sits at main.dart, onGenerateRoute and routes as well, i really don't know how to use it with named routes as i believe i already did what is being told on the Readme.

etbrow commented 1 year ago

@Mameng57

Remove the /landing and /login from the routes definition. If they are included there they won't resolve as part of onGenerateRoute

maulaniad commented 1 year ago

@etbrow Remove the /landing and /login from the routes definition. If they are included there they won't resolve as part of onGenerateRoute

You're right, i was confused . I thought both were required to do such operation, but in fact onGenerateRoute works like routes but with more customization.

api.flutter.dev onGenerateRoute Property

The route generator callback used when the app is navigated to a named route. ... This is used if routes does not contain the requested route.