yermakhan
yermakhan

Reputation: 51

Is there correct way to navigate in flutter through drawer?

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

Answers (2)

Dev
Dev

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

Albert
Albert

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

Related Questions