Closed lotus-x closed 4 years ago
I leave it to @jonataslaw but I do not think you should register your Controllers with Get.put() but rather use instantiate them in the GetX or GetBuilder widgets?
OnInit was designed to be used with Get.lazyPut(() => Controller()) as it is compatible with intelligent RAM management. Probably Get.put() will be compatible in the next major update, because navigation with routes will communicate with the entire dependency management system, GetBuilder/GetX can be registered on the route it was used for the first time, and arranged according to the route is removed from the stack when initialization took place with Get.put(), but certainly things currently work with Get.lazyPut(), I even recommend its use in 99% of cases, which in addition to the controller only entering memory exactly the moment it was called, it is registered in the smart RAM management.
I leave it to @jonataslaw but I do not think you should register your Controllers with Get.put() but rather use instantiate them in the GetX or GetBuilder widgets?
Yes, currently the two best approaches are, initializing Controllers in init: or using Get.lazyPut() before (with or without Binding), which will have exactly the same effect.
Thank you, I was going to ask for solution if it is the expected behavior. As I mentioned in previous issue pls mention those thing in the documentation. Or else newbies start opening issues like this xD. Also is there a documentation for binding? i mean in a different branch?
I leave it to @jonataslaw but I do not think you should register your Controllers with Get.put() but rather use instantiate them in the GetX or GetBuilder widgets?
IMO there should be a method to instantiating a controller because some controllers are in memory for entire life circle of the application and used by many widget across the app. I see it as a big feature of this library and also even other state management libraries has no such an option but only one immutable state to the entire app.
I understand, and I intend to support that too. There are currently initState (_) => methods within GetX and GetBuilder where you can also trigger events. This is a not-so-pretty solution, but if it's something immediate, you can use it. Currently, the onInit method is called as soon as the Controller is put into memory by an init method: or a lazyPut, Get.put is not part of Intelligent RAM Management, so it is out for now. In the future this will be possible, because the RAM management will be more flexible and configurable, and will allow the behavior you mentioned, but I'm still working on this update, it is 4pm in my country, and I need more coffee haha.
Describe the bug When registering a controller using Get.put() methods, its not trigger the onInit() override method in the controller.
Expected behavior Run onInit() method when registering a controller using Git.put()
Flutter Version: Flutter 1.17.1 • 2020-05-13 18:22 • f7a6a7906b • stable
Get Version: 2.6.3