0
class Controller extends GetxController {
  int currentIdx = ''.obs;
  void updateInt(int idx) {
    currentIdx = idx.obs;
  }
}

here is my controller. Now I put this line a widget to get idx value and assign immediately to currentIdx value:

Controller().updateInt(idx);

but .obs lines gives error in this current structure.

when I change the controller:

class Controller extends GetxController {
  RxInt currentIdx = 0.obs;
  void updateInt(RxInt idx) {
    currentIdx = idx;
  }
}

this time Controller().updateInt(idx); gives error. (RxInt not compatible int value)

how can I handle this?

1 Answers1

0

You need to declare and use like that:

RxInt currentIdx = 0.obs;
void updateInt(int id) {
    currentIdx.value = id;
  }
Maikzen
  • 1,504
  • 2
  • 6
  • 18
  • `Obx(() => Text(Controller().currentIdx.toString())),` gives always 0 result. – gegentierversuche Oct 21 '21 at 11:59
  • 1
    If you use `Controller()` always create a new instance. Declare first `Controller controller = new Controller()` and then set value to `controller.currentIdx`. In widgets you must call `controller.currentIdx.value.toString()` – Maikzen Oct 21 '21 at 12:19