jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.39k stars 1.63k forks source link

How can one ensure that each time entering PersonPage, it is a brand new instance of the personal home page for the respective user? #3243

Open ddxl123 opened 3 weeks ago

ddxl123 commented 3 weeks ago

For example, there is a personal home page (PersonPage) with an associated PersonController. When I go to my personal home page, find my followers list, and then visit the followers’ home pages, I end up entering the PersonPage twice.

The first time I call Get.to(()=>PersonPage(userId:1)), PersonPage and PersonController are normally instantiated, and the constructor is also called. However, the second time I call Get.to(()=>PersonPage(userId:2)), PersonPage and PersonController are not recreated.

How can one ensure that each time entering PersonPage, it is a brand new instance of the personal home page for the respective user?

I tried using Get.create/Get.spawn, but I’m not sure how to use it. Could you please provide a simple and easy-to-understand example? Thank you very much!

get: ^5.0.0-release-candidate-9.2
WorkWithAfridi commented 3 weeks ago

Why not initialize the controller inside the person page? Try doing that. Pass it required data via a model class, and initialize the controller inside the page or even better inject the controller.

mohammadzeyadeh001 commented 2 weeks ago

read this : https://github.com/jonataslaw/getx/blob/master/documentation/en_US/dependency_management.md#differences-between-methods

there is a lot to say about controller management , make sure to let ChatGPT to help you with your case scenario