简体   繁体   English

GetxController 结构

[英]GetxController structure

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:现在我把这一行作为一个小部件来获取 idx 值并立即分配给 currentIdx 值:

Controller().updateInt(idx);

but .obs lines gives error in this current structure.但是 .obs 行在当前结构中给出了错误。

when I change the controller:当我更改控制器时:

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

this time Controller().updateInt(idx);这次 Controller().updateInt(idx); gives error.给出错误。 (RxInt not compatible int value) (RxInt 不兼容 int 值)

how can I handle this?我该如何处理?

You need to declare and use like that:您需要像这样声明和使用:

RxInt currentIdx = 0.obs;
void updateInt(int id) {
    currentIdx.value = id;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM