Pixxu Waku
Pixxu Waku

Reputation: 443

Pop certain screens and push a screen in flutter

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?

Upvotes: 2

Views: 2659

Answers (2)

Fahmida
Fahmida

Reputation: 1210

Okay you can do that using Navigator.pop(context), before pushing ScreenFour, use Navigator.pop twice. That would do BaseScreen >> ScreenOne >> ScreenFour.

Upvotes: 2

Aravind Aji
Aravind Aji

Reputation: 154

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

Upvotes: 1

Related Questions