Reputation: 51
I am newbie in Flutter. I want to ask is there correct way to navigate between screens through drawer? Because there is a problem with navigation stack.
|:-------:| |-------| |-------| |-------| |screen1|
for example if screen 1 has a navigation button and it is navigates to screen1 and it will be like this
|-------| |-------| |screen1| |screen1| |screen1|
i need something like replacement and make my navigation stack like first table
So, i tried pushName and this way https://medium.com/flutter-community/flutter-vi-navigation-drawer-flutter-1-0-3a05e09b0db9 but this give me another problem with "Could not find a generator for route RouteSettings"
Upvotes: 0
Views: 304
Reputation: 6776
For a details of navigation kindly read article
https://medium.com/flutter-community/flutter-push-pop-push-1bb718b13c31
Use pushReplacementNamed instead of pushNamed
drawerButton(
labelText: "Новости",
onTap: () => Navigator. pushNamed(context, Routes.newsPage),
),
becomes
drawerButton(
labelText: "Новости",
onTap: () => Navigator. pushReplacementNamed(context, Routes.newsPage),
),
Upvotes: 1
Reputation: 11
Try just using Navigator.of(context).pushReplacement(context, MaterialPageRoute(builder:(BuildContext context) => YourScreen()));
. It should work and it replaces the current screen.
Upvotes: 1