getController<GetxController> method

GetxController getController<GetxController>({
  1. String tag = '',
  2. required GetxController init(),
  3. bool isLazyPut = false,
  4. dynamic doIfRegister(
    1. GetxController controller
    )?,
  5. bool shouldDoWhenRegistering = false,
  6. bool permanent = false,
  7. bool shouldPut = true,
})

Implementation

GetxController getController<GetxController>(
    {String tag = '',
    required GetxController Function() init,
    bool isLazyPut = false,
    Function(GetxController controller)? doIfRegister,
    bool shouldDoWhenRegistering = false,
    bool permanent = false,
    bool shouldPut = true}) {
  GetxController controller;
  if (Get.isRegistered<GetxController>(tag: tag)) {
    controller = Get.find<GetxController>(tag: tag);
    doIfRegister?.call(controller);
  } else {
    controller = init.call();
    if (shouldDoWhenRegistering) {
      doIfRegister?.call(controller);
    }

    if (shouldPut) {
      if (isLazyPut) {
        Get.lazyPut<GetxController>(() => controller, tag: tag);
      } else {
        Get.put<GetxController>(controller, tag: tag, permanent: permanent);
      }
    }
  }
  return controller;
}