1

I have an app with multiple pages where some pages are skip depending on the user selection...

for example, I have the following page

details.dart

contact.dart

address.dart

code.dart

summary.dart

I would like to go to another page from any of the above pages...However, I want first check to see if they are in the stack and then pop to it. Otherwise push that page onto the stack

How do I do this in Flutter

1
  • Perhaps the method Navigator.of(context).canPop(). Have a look at this medium page. It has some useful information on pushing and popping. link.medium.com/9OxEJw0ZPY Commented Aug 3, 2019 at 0:06

3 Answers 3

2

I think you might want to use Navigator.of(context).pushNamedAndRemoveUntil or Navigator.popUntil.

They are very similar however like the name suggests pushNamedAndRemoveUntil pushes a new route when the predicate matches, while popUntil re-uses an existing Route/Widget in the tree.

You can read more about them on this wonderful Medium post explaining all options in greater detail.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks but how do you tell if the route is not on the stack
you can use onUnknownRoute .
0

You can use routes inside materialApp, after home

return MaterialApp(
    home:... ,
    routes:{
       "/routeName" : (context) => PageRoute()
    }

and then call route name from any pages Ex : app in Contact page need to move to PageRoute

//Contact Page
  ... 
 onTap:(){
   Navigator.pushReplacementName(context,'/routeName');
   }

Comments

0

just use multiple Navigator.pop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.