'Flutter - How to access model object across screens with GetX?

I have 3 screens A, B, C

When I shift from A--> B, I pass the model object as an argument, and then I access it on screen B. Now, when I press Back button on Screen C, I come back to screen B. Now the model object is empty since I am not passing any data from screen C.

How do I access the model on screen B when coming back from screen C. Can I maintain a common model object using GetX. If yes, how?

Those who are going to ask what I have tried, I am passing and receiving the model as an argument, from A to B. And I haven't tried maintaining the model state using GetX since I don't know how to do it.



Solution 1:[1]

If the first controller is not disposed you can access the controller from anywhere using Get.find()

Controller controller = Get.find(Controller);

and to access the data just the same way like when initializing it:

contrller.objName

If you are using the same controller most of the times just make a static instance of it inside the controller:

class Controller extends GetxController {
  static Controller to = Get.find();
}

then access the static instance:

final Controller Controller = Controller.to;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LMech