Search code examples
androidfluttermobileflutter-layout

Flutter : delete just one page from back stack


So, i know that this code will removes all of the routes except for the new /login.:

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

now i want to remove just one page from the back stack..

Example : To create a new group, i dislpay a 'Create new group' page that contain some information (Enter page name, Enter page category ...). On submitting we pass to the new group details.. But when i click to the back button, i don't want to return to the 'Create new group' page.


Solution

  • pushReplacementNamed will replace the latest one with a newly added navigator screen

    With Named:

    Navigator.of(context).pushReplacementNamed('/login');
    

    Without Named:

    Navigator.pushReplacementNamed(context, '/login')