how to use 2 getx controllers inside each other?

Issue

I would like to use 2 controllers inside each other, but the problem is that one of them has to be initialized before the other one. For example

class FirstController extends GetxController {
  SecondController _secondController = Get.find<SecondController>(); 
}
class SecondController extends GetxController {
  FirstController _firstController = Get.find<FirstController>();
}

I used both put and lazyPut but nothing worked for me. Is there any way to do so?

Solution

So I managed to solve this problem by removing the declaration of the second controller in the first controller, and used this inside a method.

void myMethod()
{
Get.find<SecondController>().methodName();
}

Answered By – Ali Alqallaf

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *