Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unhandled Exception: Stack Overflow , Flutter GetXController is being initialized for 2000 times

I’m putting my GetXController only once on the home page using :

class NewOrdersList extends StatelessWidget {

  final OrdersController ordersC = Get.put(OrdersController());
...

then whenever I need the controller I simply use

  OrdersController ordersC = Get.find();

and the controller itself:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  @override
  void onInit() {
    trackLocation();
    super.onInit();
  }

at the end of the function trackLocation(); I use OrdersController ordersC = Get.find(); because I need to access a variable inside the controller.

but when u launch the application I see that the controller has been initialized thousands of times.

enter image description here

>Solution :

You don’t need to write Get.find() everytime if you are using controller in same class. If you need to access your OrderController's instance in some other class, then and only then you can use Get.find. And don’t write OrderController ordersC = Get.find() after trackLocation(). Because once you initialize your controller (Either put or find) , then you can access all variables from it. Never initialize your controller multiple time in your code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading