0

In bloc class, once the api return a success status, I want it return to logOut page. When back button is clicked, the app should exit.

 Navigator.pushReplacementNamed(context, LoginOut.ROUTE);

When I click back button, I expect the app will exit, but it back to previous page instead. I thought pushReplacementNamed should work?

Hoo
  • 1,806
  • 7
  • 33
  • 66

3 Answers3

1

I got a solution to this, by using this two code the problem solved

Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.of(context).pushReplacementNamed(MainScreen.routeName);

By the way i got helped from this reference https://stackoverflow.com/a/57579412/13827340

hope this could help someone ...

Spsnamta
  • 479
  • 6
  • 11
0

When you use Navigate.push from firstPage to secondPage , and then use Navigator.pushReplacement to Navigate From SecondPage to thirdPage , In this case PushReplacement will not Exit your App. (it will pop from thirdPage to FirstPage).

  • I am using `pushReplacementNamed` form `splash screen` > `login page` > `splash screen` > `home page` so their is only `pushReplacementNamed` and not just `pushName`. so why this issue ? – princeoo7 Mar 20 '20 at 09:38
0

Just simply add the below code:

Navigator.of(context).pushNamedAndRemoveUntil('/loginScreen', (route) => false);