'Flutter Navigate to a Page as Root page

Currently, I have Navigation Stack

PageA => PageB => PageC

I want to pus Push PageD as the root page

So the final result would be

=>PageD

How can I achieve that using Flutter?



Solution 1:[1]

You can use pushNamedAndRemoveUntil like this-

Navigator.of(context).pushNamedAndRemoveUntil('/screenD', (Route<dynamic> route) => false);

(Basically pop all - A, B and C and then push D) Refer this for details.

Solution 2:[2]

Take a look at this blog right here.

https://medium.com/flutter-community/flutter-push-pop-push-1bb718b13c31

Your exact scenario is at pushNamedAndRemoveUntil section.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Keerti Purswani
Solution 2 Archie G. QuiƱones