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
My thoughts are you shouldn’t use
Navigator.of(context).pushReplacement(.....)
orNavigator.of(context).pop()
either. Just use the normalNavigator.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.
use both
and
It will redirect you to new page and also pop up dialogue box