Flutter, conditional navigation / routing using GetX

Issue

Lets say that there is a way to enter the same screen from different places:

home screen -> final screen

second screen -> final screen

third screen -> final screen

etc…

how can I know from which screen I entered from? Because I need to make my own back button (default back button doesn’t reset the state of the previous screen, and the state needs to reset ) I can’t seem to find the example for the problem.

Can you use if statement for that?

Also I’m using GetX package

Desired outcome:

home screen -> final screen (back button)-> home screen

second screen -> final screen (back button)-> second screen

third screen -> final screen (back button)-> third screen

Solution

Instead of Get.back() or Get.toNamed(NameOfTheScreen), use
Get.toNamed(Get.previousRoute), it works perfectly. It navigates to the correct previous screen, and resets the state of that screen

Answered By – Lovro

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *