GetX 不显示更新值

GetX not showing the updated value

我正在尝试一个简单的弹出窗口,每次我按下 'Use' 按钮时它都会增加。使用 print 命令,每次按下时它都会显示正确的当前值。但对于 Text 本身,它只是保持一个常数值。有什么建议可以解决这个问题吗?谢谢!

  showUsePopup() async {
    AwesomeDialog(
      context: globalScaffoldKey.currentContext!,
      dialogType: DialogType.NO_HEADER,
      dismissOnTouchOutside: false,
      headerAnimationLoop: false,
      animType: AnimType.SCALE,
      body: Column(
        children: [
          Row(
            children: [
              Text('${controller.numOfItemObs.value}'),
              ElevatedButton(
                onPressed: () {
                  controller.numOfItemObs.value++;
                  print('Current value: ${controller.numOfItemObs.value}');
                },
                child: const Text('Use'),
              ),
            ],
          ),
        ],
      ),
      showCloseIcon: false,
      btnOkOnPress: () async {},
    ).show();
  }

您需要用 Obx 包装文本小部件。只要发生更改,它就会更新 Text 值。这是您可以遵循的示例。

Obx(
      () => Text('${controller.numOfItemObs.value}')')
   ),