I am making a drawer in Flutter. And a refer and earn section in it. Now, whenever I click on that, I will be redirected to refer page. And when I will press back button on appbar, I come back to the drawer widget. This is working fine and accordingly. Now, I want that whenever I click on back button from refer page, my drawer should be closed and I reach to the main screen. How should i do it?
CodePudding user response:
It's referred to go back to the first page where you start. Whether this route is the bottom-most active route on the navigator. If isFirst and isCurrent are both true then this is the only route on the navigator (and isActive will also be true).
Navigator.of(context).popUntil((route) => route.isFirst);
CodePudding user response:
You can use this below method to navigate back-
Navigator.popUntil(context, (route) => false);
CodePudding user response:
I figured it out. Pretty simple, when I tap, pop the drawer using Navigator.pop(context) and then Navigate to the next page. So, when I clicked back arrow, I got to the main/previous screen.
