Reputation: 899
this is the scenario of my app: Splash Screen -> Login Screen -> Home Screen
I have WillPopScope
in my Login Screen and also in my Home Screen.
If the user has successfully logged in, I use:
Navigator.push(
context, MaterialPageRoute(builder: (context) => HomeScreen()));
The problem I have is that, I am now in my Home Screen but when I try to press the back button of my phone, the WillPopScope
of my Login Screen is being triggered instead of the Home Screen ?
I'm new to flutter and I'm having trouble with this simple logic. Please help.
Upvotes: 0
Views: 1218
Reputation: 774
In the Login Screen add Navigator.pop(context)
before call Home Screen.
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreen()));
Upvotes: 0
Reputation: 11881
When you are in Login Screen you need pop Login Screen from stack and push Home screen into it. You can do that with:
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeScreen()))
Upvotes: 1