Search code examples
flutterdartflutter-layoutflutter-test

Multiple WillPopScope?


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.


Solution

  • 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()))