[Flutter][Getx][状态管理]使用StateManagement

[Flutter][Getx][State Management] using StateManagement

我正在尝试应用 Getx 状态管理来更新我的屏幕(可能是响应式的?),
我看过官方的getx github 文档。这就是我尝试过的。

1.设置我想要的变量使其响应 .obs

<例如 1>

 List blueBan = List<String>.filled(5, champIcon, growable: false).obs;  

 List redBan = List<String>.filled(5, champIcon, growable: false).obs;  

============================================= ================================================ ===

2。将 Widget 设置为我想要更新的 Obx(()=> Widget)(像使用 setState 方法一样更新)

<例如 2>

   Widget banContainer(List banList, String team, int n) {

      return Container(
      ...

          child: Obx(

            () => DragTarget<String>(

              onWillAccept: (value) {

                banTemp = value;

                return true;  

*变量banList是blueBan,redBan的引用
我正在使用它 banContainer(blueBan, 'blue', 0)

↓ 这是我得到的错误信息

════════ Exception caught by widgets library ═══════════════════════════════════
The following message was thrown building Obx(has builder, dirty, state: _ObxState#1202f):
      [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.

The relevant error-causing widget was
Obx
lib\…\ui\BanPick.dart:230
When the exception was thrown, this was the stack
#0      RxInterface.notifyChildren
package:get/…/rx_core/rx_interface.dart:29
#1      _ObxState.build
package:get/…/rx_flutter/rx_obx_widget.dart:54
#2      StatefulElement.build
package:flutter/…/widgets/framework.dart:4691
#3      ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4574
#4      StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4746
...
════════════════════════════════════════════════════════════════════════════════

然而我在我的 List 变量上插入了 .obs,它说“如果你看到这个错误,你可能没有将任何可观察变量插入 GetX/Obx”

感谢阅读

您必须使用 RxList 进行观察,然后它才能在 obx 中工作,否则您必须使用 getbuilder 并调用 update() 进行 ui 更改