如何更新flutter Dart中的数据提供商
我有几件事的列表,每个列表都有自己的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二次
dataid
不再是空的,因此未设置。At second time
DataID
is not anymore empty and therefore not set.