如何在RxStatus.success()函数中Obx



我使用CheckboxListTile来输入复选框。

这是一个从消防仓库中检索数据列表的功能

void initDoctorCategory() {
DoctorCategoryService().getListDoctorCategory().then((doctorCategory) {
change(doctorCategory, status: RxStatus.success());
});
}

这是我的小部件。我不能在doctorCategory[index]中使用obx更新值。值:

body: controller.obx(
(doctorCategory) => Container(
child: ListView.builder(
itemCount: doctorCategory!.length,
itemBuilder: (BuildContext context, int index) {
return Obx(() => CheckboxListTile(
title: Text(doctorCategory[index].categoryName!),
value: doctorCategory[index].value,
onChanged: (value) {
doctorCategory[index].value = value!;
// Get.back();
},
));
},
),
),
),

我得到错误:

[Get]检测到对GetX的不当使用。您应该只对将要更新的特定小部件使用GetX或Obx。如果您看到这个错误,您可能没有在GetX/Obx中插入任何可观察的变量或者将它们插入到GetX认为适合更新的范围之外(示例:GetX=>HeavyWidget=>variableObservable(。如果您需要更新父窗口小部件和子窗口小部件,请将它们封装在Obx/GetX中。"quot">

如何解决此问题?如何在RxStatus.success((中使用Getx?

试试这个:

body: Container(
child: Obx(() {
return ListView.builder(
itemCount: doctorCategory!.length,
itemBuilder: (BuildContext context, int index) {
return CheckboxListTile(
title: Text(doctorCategory[index].categoryName!),
value: doctorCategory[index].value,
onChanged: (value) {
doctorCategory[index].value = value!;
},
);
},
);
}),
),

确保您的控制器中有Get.put或Get.lazyPut

最新更新