flutter You should only use GetX or Obx for the specific widget that will be updated

错误日志
 [Get] the improper use of a GetX has been detected.
      You should only use GetX or Obx for the specific widget that will be updated.
      If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
      or insert them outside the scope that GetX considers suitable for an update
      (example: GetX => HeavyWidget => variableObservable).
      If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
错误代码
class _GridViewExtent extends GetView {
  const _GridViewExtent({super.key});

  @override
  Widget build(BuildContext context) {
    return GridView.extent(
      .........
      children: initGridCount(),
    );

List initGridCount() {
    List list = [];
    for (int i = 0; i < controller.listGenBean.value.length; i++) {
      GeneratedResultModel generatedResultModel = controller.listGenBean.value[i];
      list.add(GestureDetector(
        onTap: () {
           ....
        },
        child: Stack(
          children: [
            Obx(() => Positioned(
                   ...
                child: Offstage(
                  offstage: !generatedResultModel.isSelect,//错误问题就在这里,我想监听的这个参数,不属于RxBool类型
                   ....,
                )))
          ],
        ),
      ));
    }
    return list;
  }

class GenerateResultController extends GetxController{
  RxList listGenBean = [].obs;
}

class GeneratedResultModel{
   bool isSelect = false; //原因是这个不是RxBool类型导致的
}

简单来说,你使用了Obx进行监听,但是你这监听的数据里面没有任何一个参数属于RxString或者RxBool等的类型

解决方案
class GeneratedResultModel{
   RxBoolisSelect = false.obs; //这个不是RxBool类型导致的
}
我的博客

简书
csdn

你可能感兴趣的:(flutter)