obx中的flutter getx rxlist显示窗口小部件

发布于 2025-01-25 01:10:58 字数 1490 浏览 1 评论 0原文

嗨,我在项目上使用GetX。我有rxlist,并且我使用obx显示我的数据:

RxList dasteBandi = [].obs;



void changeTodasteBandi(int index) {
dasteBandi.removeAt(index);

}

和小部件是:

Obx(
  () => ListView.builder(
    // itemCount: catList.length,
    itemCount: taskController.dasteBandi.length,
    itemBuilder: (context, index) {
      return Container(
        decoration: BoxDecoration(
            color: themeController.isDark.value == true
                ? Colors.black.withOpacity(0.3)
                : Colors.white.withOpacity(0.8),
            borderRadius: BorderRadius.circular(16)),
        margin: EdgeInsets.symmetric(vertical: 1.h),
        child: ListTile(
          // title: Text(catList[index]),
          title: Text(taskController.dasteBandi[index]),

          leading: IconButton(
            onPressed: () {
              print(index);
              // setState(() {
              //   catList.removeAt(index);
              // });
              taskController.changeTodasteBandi(index);
            },
            icon: Icon(
              Icons.remove_circle_sharp,
              color: MyUtils.kRedColor,
            ),
          ),
        ),
      );
    },
  ),
);

当我使用此窗口小部件时,我有此错误:

widegets库捕获的异常 堆栈溢出 相关引起错误的小部件是 GetMaterialApp

堆栈溢出 相关引起错误的小部件是 obx

当我删除这条线时, itemCount:taskcontroller.dastebandi.length, 并用: itemCount:catlist.length,

使用setState()每件事都很好,但是当我将getx控制器用于列表时,我有一个错误

hi i am using getx on my project . I have RxList and i use Obx for shows my data :

RxList dasteBandi = [].obs;



void changeTodasteBandi(int index) {
dasteBandi.removeAt(index);

}

and widget is :

Obx(
  () => ListView.builder(
    // itemCount: catList.length,
    itemCount: taskController.dasteBandi.length,
    itemBuilder: (context, index) {
      return Container(
        decoration: BoxDecoration(
            color: themeController.isDark.value == true
                ? Colors.black.withOpacity(0.3)
                : Colors.white.withOpacity(0.8),
            borderRadius: BorderRadius.circular(16)),
        margin: EdgeInsets.symmetric(vertical: 1.h),
        child: ListTile(
          // title: Text(catList[index]),
          title: Text(taskController.dasteBandi[index]),

          leading: IconButton(
            onPressed: () {
              print(index);
              // setState(() {
              //   catList.removeAt(index);
              // });
              taskController.changeTodasteBandi(index);
            },
            icon: Icon(
              Icons.remove_circle_sharp,
              color: MyUtils.kRedColor,
            ),
          ),
        ),
      );
    },
  ),
);

when i use this widget i have this error :

Exception caught by widgets library
Stack Overflow
The relevant error-causing widget was
GetMaterialApp

Stack Overflow
The relevant error-causing widget was
Obx

when i am remove this line
itemCount: taskController.dasteBandi.length,
and changed it with:
itemCount: catList.length,

and use setState() every thing is fine but when i use getx controller for list i have that error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文