我犯了这个错误。我在检查是否一个接一个的时候遇到了这个错误。我不知道我写的代码是怎么工作的。我想和你商量一下它是否有效。有人能帮忙解决这个问题吗?
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.
发布于 2021-08-02 03:15:12
要使上面的代码正常工作&而不是抛出您看到的错误,isLang
必须是“可观察的”。
例如,类似于:
class LanguageController extends GetxController {
RxBool isLang = false.obs();
}
由于问题中的代码没有显示正在使用的isLang
值(即isLang.value
),我猜它是不可观察的。
在使用GetX
或Obx
小部件时,必须使用“可观察的”(RxBool
、RxInt
、Rx<Whatever>
等)。控制器内部的常规int
、bool
等不足以满足这一要求。GetX
和Obx
需要一种可观察的Rx
类型。
https://stackoverflow.com/questions/68611804
复制相似问题