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?
CodePudding user response:
You need to declare and use like that:
RxInt currentIdx = 0.obs;
void updateInt(int id) {
currentIdx.value = id;
}