【问题标题】:how to use Conditional rendering with getX boolean observable如何使用带有 getX boolean observable 的条件渲染
【发布时间】:2026-01-14 21:55:02
【问题描述】:

在我的登录控制器中:

class LoginController extends GetxController {
  final GlobalKey<FormState> loginFormKey = GlobalKey<FormState>();

  late TextEditingController emailController, passwordController;
  var isloading = false.obs;    <<<<<<<<<<<<
...

在我的视图文件中:

 Container(
  color: Colors.blueGrey,
  width: double.infinity,
  height: 150,

  child: Obx(()=>
    Center(
      child: logincontroller.isloading ? CircularProgressIndicator(): Container(),

    ),
  )
)

但我不断收到此消息:

33:50:错误:“RxBool”类型的值无法分配给变量 'bool' 类型的。

【问题讨论】:

    标签: flutter flutter-getx


    【解决方案1】:

    尝试logincontroller.isLoading.value检查RxBool的值

    【讨论】:

    • 感谢您解决了这个问题:现在当 isloading 变量更改为 true 时(单击登录按钮后),循环进度指示器不会自动显示。它仅在我进行刷新/热重载后显示。
    • 基本上小部件没有重建。加载时将值从 false 更改为 true。 child: Obx(()=> Center(child: logincontroller.isloading.value ? new CircularProgressIndicator(): new Container(child: Text('hello its false')), )
    • 如何更改值?
    • 使用登录按钮对 api 进行 post 调用。 Future checkLogin() async { isloading = true.obs; //就在这里。
    • 你才是真正的 MVP。有效!你能向我解释为什么会这样吗?即使之前技术上的价值也在发生变化?
    最近更新 更多