getx icon indicating copy to clipboard operation
getx copied to clipboard

Using goRouter with Gex not disposing controller

Open 02imran opened this issue 1 year ago • 5 comments
trafficstars

I am using goroute with getx my problem is when I navigate to another page and get back my controller in not disposing. How can I fix this

02imran avatar Dec 02 '23 18:12 02imran

@02imran GetXController doesn't automatically bind itself with go_router. To dispose of GetXController automatically, you should use Bindings. However, if you want to dispose of the controller manually, you can delete it in the dispose method of your widget. By doing this, the controller will be disposed whenever your route or page gets disposed of. When you revisit that route by Get.find(), a new controller instance will be created. Don't forget to set fenix:true in Get.lazyPut when injecting your controller.

moo-kesh avatar Dec 08 '23 14:12 moo-kesh

@02imran GetXController doesn't automatically bind itself with go_router. To dispose of GetXController automatically, you should use Bindings. However, if you want to dispose of the controller manually, you can delete it in the dispose method of your widget. By doing this, the controller will be disposed whenever your route or page gets disposed of. When you revisit that route by Get.find(), a new controller instance will be created. Don't forget to set fenix:true in Get.lazyPut when injecting your controller.

Can you give me a example

02imran avatar Dec 08 '23 15:12 02imran

GetX navigation is what allows you to remove controllers when a page leaves the stack. You basically have two ways to do this: 1: use GetBuilder to inject your controllers. 2: use StatefulWidget with Get.put() in initState and Get.delete() in dispose.

jonataslaw avatar Dec 08 '23 21:12 jonataslaw