Flutter [Get] 检测到一个 GetX 的不当使用

问题描述

我收到了这个错误。我在检查是否一个接一个时遇到此错误。我不确定我写的代码是如何工作的。我想咨询你是否有效。任何人都可以帮助解决这个问题并解决它吗?

return Obx(() => _languageController.isLang == ''
    ? LanguageView()
    : controller.getCurrentUser == null
        ? LoginView()
        : _countryController.isLanguage == false
            ? CountryView()
            : HomeView());

[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.

解决方法

为了使上面的代码正常工作且不抛出您看到的错误,isLang 必须是“可观察的”。

例如,类似于:

class LanguageController extends GetxController {
  RxBool isLang = false.obs();
}

由于问题中的代码没有显示正在使用的 isLang 的值(即 isLang.value),我猜它不是可观察的。

使用 GetXObx 小部件时,您必须使用“observables”(RxBoolRxIntRx<Whatever> 等)。控制器中的常规 intbool 等不足以满足该要求。 GetXObx 需要 Rx something 的可观察类型。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...