如何更新flutter Dart中的数据提供商

发布于 2025-01-26 20:10:33 字数 613 浏览 1 评论 0原文

我有几件事的列表,每个列表都有自己的ID。每当单击提供商时,我想将该ID传递给提供商。但是截至目前,当我第一次单击列表中的项目一时,项目一的ID将传递给提供商,但是当我再次单击列表中的其他项目时,该项目的ID不会更新在提供商中。 我想知道,每当单击新项目时,如何更新提供商的数据。

这是我的代码:

  • 传递数据
onTap: () async {
  Provider.of<providerFile>(context, listen: false).setdataID(DataID);
  Navigator.push(context, MaterialPageRoute(builder: (context) => NextPageHome(DataID: DataID)));
},


  • 提供商文件,
String DataID = '';

  void setdataID(String pin) {
    if (DataID.isEmpty) {
      DataID = pin;
      notifyListeners();
    }
  }

谢谢,程序员。

I have a list of a few things and each has its own ID. I want to pass that certain ID to the provider whenever it's clicked. But as of now, when I click on ITEM ONE in the list for the first time, the ID of ITEM ONE is passed to the provider, but when I click again on a different item in the list the ID of that item is not updated in the provider.
I want to know, how can I update the data of the provider every time a new item is clicked.

here are my codes:

  • Passing Data
onTap: () async {
  Provider.of<providerFile>(context, listen: false).setdataID(DataID);
  Navigator.push(context, MaterialPageRoute(builder: (context) => NextPageHome(DataID: DataID)));
},


  • Provider File
String DataID = '';

  void setdataID(String pin) {
    if (DataID.isEmpty) {
      DataID = pin;
      notifyListeners();
    }
  }

Thanks, programmers.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2025-02-02 20:10:33

第二次dataid不再是空的,因此未设置。

At second time DataID is not anymore empty and therefore not set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文