skip to Main Content

In Flutter, I have a side drawer with a menu of target pages. When I click on one of the menu items, the app should close the drawer and open the target page.

Should I call Navigator.of(context).pop() to close the drawer and in the next line call Navigator.of(context).pushReplacement(.....) ?

Since I have already popped the drawer widget, will it create problems if there is any code after pop()? It sounds logical that the side drawer should not be on the page stack once its works is done. The code works fine without calling pop(). But If do not pop the drawer at all, will there be any memory leaks or similar issues?

2

Answers


  1. My thoughts are you shouldn’t use Navigator.of(context).pushReplacement(.....) or Navigator.of(context).pop() either. Just use the normal Navigator.push(context,NextPage()).then((value) {Navigator.of(context).pop();})

    Here you’ll be routed to the next page and when navigating back, the drawer will be closed.

    Login or Signup to reply.
  2. use both

    Navigator.of(context).push()
    

    and

    Navigator.of(context).pop
    

    It will redirect you to new page and also pop up dialogue box

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search