Search code examples
flutternavigationflutter-getx

Flutter Get Navigation - Removing route in the middle


I know there are some duplicate/similar questions, I read them all but I can't get the right answer.

I'm using Getx to navigate between screens(Get.toNamed()) and I was just wondering if there's any way to remove a certain route from the navigation stack. Let's say I have the following routing for my sample social networking app:

main screen -> post screen -> profile screen -> (another) post screen

I want to remove the first post screen and add a new post screen after the profile screen but able to go back to the profile screen when I press the back button from the second post screen(another back button goes to the main screen and if I go to profile screen(again) from the second post screen, the first profile screen will also be removed). The reason I want to do this is because I want the screens to have only one instance.

I tried saving the Get.rawRoute of post screen and called Get.removeRoute(route) when opening the second post screen from the profile screen but I get "'route._navigator == this': is not true." assertion.

Is it impossible because it's a stack? but.... I just don't think this is impossible, there must be a way...

Help me Flutter Masters!


Solution

  • Just kidding, saving the Get.rawRoute of the post screen and calling Get.removeRoute(route) before opening another post screen works just fine, I made a mistake. HAHAHAHAHAHAHA