Reputation: 5155
If an initial route is defined, Navigator builds the stack with two routes: the initial one and '/' route.
Check out the example on the link showing that HomePage as the initial route has a back button that returns to '/' route.
How to make an initial route the only route on the stack?
Upvotes: 2
Views: 720
Reputation: 309
Try as this, initialRoute:'/' in MaterialApp
const String homeRoute = '/';
void main() {
runApp(
MaterialApp(
title: 'Example',
initialRoute:homeRoute,
onGenerateRoute: generateRoute
),
);
}
Upvotes: 0
Reputation: 9008
So when you use, switch
, you return the null
in your default
, which sets the HomePage
as the initialRoute
, and let the machine know that, the initialRoute
is the one, and nothing to be returned in the Stack
, except HomePage
. Hence, you don't get to see the back button anymore.
switch (settings.name) {
case HomePage.route:
return MaterialPageRoute(builder: (_) => HomePage());
case OverviewPage.route:
return MaterialPageRoute(builder: (_) => OverviewPage());
default:
// this would do the job
return null;
}
I have made changes in the link also, you can try that too. Try out this link, and let me know.
Upvotes: 2