I have multiple screens and I'm using named routes in flutter using getx package. The problem I'm facing is I'm able to navigate to any other screen when tapped on push notification, but when I go back from that screen my app closes. But expected outcome is when navigating back I should go to home screen and app should not close. Please help
Asked
Active
Viewed 898 times
3
-
Are you using Navigator 2.0 or the old version? – Developer Extraordinare Mar 10 '22 at 17:16
-
Could you potentially access `Navigator.of(context).pages` and insert a page at index 0? – Developer Extraordinare Mar 10 '22 at 17:30
-
I'm using route management provided by getx package i think it uses navigator 2.0 only. Thanks for the solution, I want to handle this logic in single part of my app such that it works for all screens, for this where should I use this code ? – Mickey Mar 11 '22 at 02:40
1 Answers
0
Try using the following when back button is pressed:
Navigator.popAndPushNamed(context, '/homeScreen')

Jeremy Caney
- 7,102
- 69
- 48
- 77

Samia Ashraf
- 195
- 5
-
Ok thanks, So i was handling all named routes in single class, how can manage above code in single place? Where should I use this code so that it works for all screens ? – Mickey Mar 11 '22 at 02:38