skip to Main Content

I encountered a strange problem. There was no exception in my local debugging, but a gray interface appeared online. I initialized it and thought that Getx could not find the corresponding GetxController.

The phenomenon of the problem is: no error will be reported when entering the page for the first time, but an error will be reported after entering the page for the second time. And when you call Get.back() to return to the previous level, an error will be reported only if you enter again. If you return by sliding sideways, no error will be reported.

If Get.back() returns to the upper-level page, waits for 1~2 seconds, and then enters again, no error will be reported. Have you ever encountered such a magical problem? I’m not sure if it has something to do with the life cycle.

My code doesn’t have much logic. My UI interface hierarchy is like this. Class A is the parent view, classes B, C, and D are subviews (separately encapsulated). Then I put a view model in A and find it in B, C, and D.

2

Answers


  1. It’s hard to say without seeing any code. But I think what happens is that the controller got disposed off when navigating to another route/page. What can help then is to use a lazyPut in combination with fenix: true. This way it can be restored after it was disposed. So instead of

    Get.put(MyController());
    

    or

    Get.lazyPut(() => MyController());
    

    do this instread:

    Get.lazyPut(() => MyController(), fenix: true);
    
    Login or Signup to reply.
  2. This Type of error usually occurs when you try to get "GetXControoller" controller without definning it.
    For example:

    final MYGetController controller = Get.find();
    

    First you need to initialize it

    final controller = Get.put(MYGetController);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search