I pushed(with named routes) few screens like so,
BaseScreen >>(pushNamed) ScreenOne >>(pushNamed) ScreenTwo >>(pushNamed) ScreenThree >>(pushNamed) ScreenFour
While I am at ScreenFour what I wanted was that instead of just pushing ScreenFour to the stack, to remove ScreenThree and ScreenTwo from the stack and then have ScreenFour at top of the stack.
so at the end while im at ScreenFour the stack should look like,
BaseScreen >> ScreenOne >> ScreenFour.
How can I achieve this in flutter?
CodePudding user response:
Okay you can do that using Navigator.pop(context), before pushing ScreenFour, use Navigator.pop twice. That would do BaseScreen >> ScreenOne >> ScreenFour.
CodePudding user response:
You can use Navigator.pushAndRemoveUntil() for 2nd and 3rd screen and use normal Navigator.push for 4th screen.
Thus it will be possible.
Learn more about pushAndRemoveUntil here
