0

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"

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
yermakhan
  • 49
  • 3

2 Answers2

1

Try just using Navigator.of(context).pushReplacement(context, MaterialPageRoute(builder:(BuildContext context) => YourScreen()));. It should work and it replaces the current screen.

Albert
  • 11
  • 1
  • `drawerButton(labelText: "Новости", onTap: () => Navigator.pushNamed(context, Routes.newsPage), ),` I tried this but same problem – yermakhan Jun 23 '21 at 06:57
1

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),
            ),
Dev
  • 6,628
  • 2
  • 25
  • 34