Reputation: 2166
I need to transition between my screens with named routes. But when I use more than 1 route it transitions with the default transition and not the one from the flutter_page_transitions library.
This doesn't work:
initialRoute: '/first',
routes: {
'/first': (context) => First(),
'/second': (context) => Second(),
'/third': (context) => Third(),
},
onGenerateRoute: (settings) {
switch (settings.name) {
case '/first': {
return PageTransition(
child: First(), type: PageTransitionType.fade);
}
break;
case '/second': {
return PageTransition(
child: Second(), type: PageTransitionType.fade);
}
break;
case '/third': {
return PageTransition(
child: Third(), type: PageTransitionType.fade);
}
break;
default: {
return null;
}
}
},
This works
onGenerateRoute: (settings) {
switch (settings.name) {
case '/first': {
return PageTransition(
child: First(), type: PageTransitionType.fade);
}
break;
default: {
return null;
}
}
},
Upvotes: 0
Views: 290
Reputation: 2166
Thanks guys! Solution: I commented out the routes
home: First();
//initialRoute: '/first',
/*routes: {
'/first': (context) => First(),
'/second': (context) => Second(),
'/third': (context) => Third(),
},*/
onGenerateRoute: (settings) {
switch (settings.name) {
case '/first': {
return PageTransition(
child: First(), type: PageTransitionType.fade);
}
break;
case '/second': {
return PageTransition(
child: Second(), type: PageTransitionType.fade);
}
break;
case '/third': {
return PageTransition(
child: Third(), type: PageTransitionType.fade);
}
break;
default: {
return null;
}
}
},
Upvotes: 1
Reputation: 3165
You shouldn't have the same route in both routes: and onGenerateRoute. They are mutually exclusive. So choose which code block you want to process your route.
OnGenerateRoute picks up routes that are not specified in routes:
Upvotes: 1