how to let get.back take some argument

my wish is when user hits back button on Page B to jump back to Page A, Get.back() is activated, but it should take an argument such as newCreatedId, I found something like Get.back(result: [newCreatedId]);, but I didn’t find tutorial how to let Page A get this argument, plz help me thanks!

>Solution :

the Get.back() with the result property is exactly what you need, and I will explain it to you:

so using Getx, when you’re trying to navigate to another route, we usually just call Get.to() directly:

Get.to(MyOtherScreen());

right?

in order to get some data from the MyOtherScreen(), it’s different a little bit, instead of calling just Get.to() directly we need to assign its call to a variable like this:

var futureData = Get.to(MyOtherScreen());

even if you assign it to a variable like this, it still works fine and navigates to MyOtherScreen() as expected.

after navigating, we are now in the MyOtherScreen(), after the user did what he needs to do on that page and wants to pop/back of that page with some data, you need to call:

Get.back(result: theDataFromMyOtherScreen);

what this will do:
it will close the MyOtherScreen() page and will store the theDataFromMyOtherScreen inside of the first variable where we assigned to it the Get.to().

so the result after popping the page will be:

var futureData = Get.to(MyOtherScreen()); // futureData == theDataFromMyOtherScreen

now if you try to print it as example:

print(futureData); // will print the value of theDataFromMyOtherScreen

and every time you do the same routing process, it will store new data in that variable.

to recap:
the Get.to() we called inside the variable navigates with us to the other page, and Get.back() will return us to the previous page with the value stored in the result property, so you can think of them that they are linked.

Leave a Reply