Search code examples
flutterflutter-navigation

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

  • 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.