1

I tried these lines of code,

    `Navigator.pushReplacement(context,
    MaterialPageRoute(builder: (context) => object),`

But this shows the problems like- I have to close the replaced page twice then close the application. (Like, If I replace the login page with dashboard then to close application, I have to press back button and again other times back button)

2
  • 1
    In this case, there is another route in the stack that you have not told us about. Commented Apr 5, 2019 at 18:09
  • the object comes from the parameter. It can be Dashboard(), ProfileDashboard(). Commented Apr 6, 2019 at 0:31

1 Answer 1

4

As @creativecreatorormaybenot pointed out there is another route in the stack that you haven't mentioned.

Nevertheless, what you should do is push and remove everything below the stack.

Here is the code

Navigator.pushAndRemoveUntil(
  context,
  MaterialPageRoute(builder: (context) => object),
    (r) => false
);
Sign up to request clarification or add additional context in comments.

4 Comments

Are you telling about object used there in the code above? That is Class of stateful class like Dashboard(),Profile().
not it is not releated to object. I mean pushReplacement is not working because there is not 1 route in the stack when you call it there are 2 (you might have pushed another route before login)
I mean push replacement works and i loaded dashboard. After that, to close the app with back button of mobile, I have to close that app twice.
In need some context there some bug in your code somewhere which is giving you that behaviour. My code should any how work and do what you intend

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.