'What is best approach to use GetXController inside function?

I'm using GetxController with these approachs.

Appraoch 1:

final myController = Get.put(MyController());
void printSomething() {
  print(myController.myValue.value);
}
printSomething();

Appraoch 2:

final myController = Get.put(MyController());
void printSomething(MyConroller controller) {
  print(controller.myValue.value);
}
printSomething(myController);

Approach 3:

final myController = Get.put(MyController());
void printSomething(String toPrint) {
  print(toPrint);
}
printSomething(myController.myValue.value);

Three codes work same. What is the best approach to do this?



Solution 1:[1]

I am in favor of approach 3

final myController = Get.put(MyController());
void printSomething(String toPrint) {
  print(toPrint);
}
printSomething(myController.myValue.value);

since if you want to print a string or whatever at the time, just pass the string and ready the "simple" primitive type on the other hand if you send the controller type you marry that it is strictly the type " mycontroller" but all you want is to print a string

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexis Montoya