列表视图错误flutter getx错误已检测到GetX的不当使用

发布于 2025-02-14 00:24:46 字数 1749 浏览 0 评论 0原文

我正在尝试在简单的ListView上使用GETX,但它显示出[GET]检测到GetX的不当使用的错误。

  Widget getBody() {
    var size = MediaQuery.of(context).size;
    final controller = Get.put(PassionController());

    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.only(left: 30, right: 30),
        child: Column(
          children: [
            GetX<PassionController>(
                builder: (_) => ListView.builder(
                    itemCount: controller.passionItems.length,
                    itemBuilder: (context, index) {
                      return ListTile(
                        title:
                            Text('Number: ${controller.passionItems[index]}'),
                      );
                    })),
            GestureDetector(
              onTap: () {
                Navigator.push(
                    context, MaterialPageRoute(builder: (_) => MyHomePage()));
              },
              child: Container(
                width: size.width,
                height: 55,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30), color: Colors.white
                    // gradient:
                    //     LinearGradient(colors: [primary_one, primary_two])

                    ),
                child: Center(
                  child: Text(
                    "Continue",
                    style: TextStyle(
                        color: kPrimarycolor,
                        fontSize: 18,
                        fontWeight: FontWeight.w500),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

我也尝试使用GetXbuilder,但显示同样的错误。我已经在main上包裹了材料。

I am trying to use Getx on simple ListView but its showing error that [Get] the improper use of a GetX has been detected.

  Widget getBody() {
    var size = MediaQuery.of(context).size;
    final controller = Get.put(PassionController());

    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.only(left: 30, right: 30),
        child: Column(
          children: [
            GetX<PassionController>(
                builder: (_) => ListView.builder(
                    itemCount: controller.passionItems.length,
                    itemBuilder: (context, index) {
                      return ListTile(
                        title:
                            Text('Number: ${controller.passionItems[index]}'),
                      );
                    })),
            GestureDetector(
              onTap: () {
                Navigator.push(
                    context, MaterialPageRoute(builder: (_) => MyHomePage()));
              },
              child: Container(
                width: size.width,
                height: 55,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30), color: Colors.white
                    // gradient:
                    //     LinearGradient(colors: [primary_one, primary_two])

                    ),
                child: Center(
                  child: Text(
                    "Continue",
                    style: TextStyle(
                        color: kPrimarycolor,
                        fontSize: 18,
                        fontWeight: FontWeight.w500),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

I also try GetxBuilder but same error showing. I already wrap GetMaterial on main.dart

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

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

发布评论

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