Basically why the framework says that Get.to(() => page) is better than the other method? For me they are the same but I'd like to know if there's any difference or impact.
I'm using the Get.to(() => page) but only because the framework says so.
There is a slight difference between both.
Get.to(page)
just uses default constructor to create new instance of the page. Meaning if your page has any dependencies, you would have to pass them as constructor arguments.
Get.to(()=>page)
creates page lazily using a closure or lambda
function. As a result, you may build the page utilising GetX's dependencies by using the Get.put()
or Get.lazyPut()
methods.
To summarize
Get.to(MyPage()); // No dependency injection
Get.to(() => MyPage()); // Allows for dependency injection