【问题标题】:Flutter [Get] the improper use of a GetX has been detectedFlutter [Get] 已检测到 GetX 使用不当
【发布时间】:2021-10-07 05:30:08
【问题描述】:

我收到了这个错误。我在检查是否一个接一个时遇到此错误。我不确定我编写的代码是如何工作的。我想咨询你是否有效。谁能帮忙解决这个问题?

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.

【问题讨论】:

    标签: flutter flutter-getx


    【解决方案1】:

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

    例如:

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

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

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

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 2021-12-14
      • 2022-01-02
      • 1970-01-01
      • 2021-05-28
      • 2021-09-22
      • 2021-10-10
      • 2021-04-16
      • 2021-03-29
      相关资源
      最近更新 更多