1

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:

  @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

1
  • 1
    Can you share your trackLocation function as well? Commented Dec 28, 2021 at 10:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.