1

I try to build a flutter app and want to navigate trough the pages. I build a drawer with a menu with several items to open new pages - that works fine.

      onTap: () {
        Navigator.of(context).pop();
        Navigator.push(
          context,
          new MaterialPageRoute(
            builder: (BuildContext context) => new Page1(),
          ),
        );
      },

By pressing on the Page1 menuitem page1 opens fine. Inside page1 I have a slidable list with "edit" and "details". I open this with

      onTap: () {
        Navigator.of(context).pop();
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (BuildContext context) => new DetailsPage(),
          ),
        );
      },

In the details Page I see all the things i wanna see, but when I press the Back button in the appBar i am back at home screen with closed drawer.

I tried to put onPressed: () => Navigator.pop(context); inside the appBar section but this doesn´t work either.

Now I got what I want by using always Navigator.push but I am sure that this is not right, so that navigator stack gets bigger and bigger.

What I do wrong? Why .pop does not bring me to the last page? Any ideas?

Thx in advance Patrick

2 Answers 2

1

Just remove the line with the Navigator.of(context).pop();in the Page1 onTap.

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

Comments

0

you can use pushReplacement in any cases you need to remove current page from stack and route to new page.

Replace the current route of the navigator that most tightly encloses the given context by pushing the given route and then disposing the previous route once the new route has finished animating in.

here is the documentation

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.