3

I have a Flutter app with GetX Controllers. The app has 6 screens and every screen has its GetxController.

Screens 1 and 2 are for the login system, while screens 3 to 6 are for the app content.

After logging in the user can go forward and back between screens 3-4-5, but when he reaches screen 6 he can only go to Screen 3 and all the previous stacks must be deleted (so he cannot go back).

1st problem: if I do a Get.offAll(() => const Screen3()) from the Screen 6, the Controller for Screen3 gets deleted and nothing works anymore. I workaround (don't know if that word exists! :D) by marking Controller3 as permanent via

Get.put(Controller3(), permanent: true)

But here comes the

2nd problem: if the user presses the logout button (that is present only in Screen 3), this time I need the Controller3 to be deleted. This time, calling Get.offAll doesn't delete the controller, nor calling Get.delete<Controller3>(), since it says

"Controller3" has been marked as permanent, SmartManagement is not authorized to delete it.

I'm stuck in this situation and I really don't know what to do

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
Ale TheFe
  • 1,540
  • 15
  • 43

2 Answers2

6

So Getx as you said let us make a GetxController permanent like this:

Get.put<Controller3>.put(Controller3(), permanent: true);.

you can't delete it normally with:

Get.delete<Controller3>();

But you have the option to delete a controller that is marked with permanent, by forcing its deletion with the force property like this:

Get.delete<Controller3>(force: true);

force Will delete an Instance even if marked as permanent.

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
  • I ended up doing this way...though I don't really know why bindings are not working... – Ale TheFe Nov 16 '22 at 14:07
  • 1
    perfect solution, i was thinking it is a mistake of the GET package as I am not deleting it manually still it gets deleted, but by doing this i got the answer as well as solutions, thanks – Chirag Mevada Feb 25 '23 at 07:14
2

1st problem: if I do a Get.offAll(() => const Screen3()) from the Screen 6, the Controller for the Screen3 gets deleted and nothing works anymore.

I didn't get the quoted part. When you route from 6 --> 3, the binding mechanism should generate the controller of screen 3 again.

By the way you can make it manually from anywhere using with

 var controller = Get.put(SomeController());
 controller.dispose();
blackkara
  • 4,900
  • 4
  • 28
  • 58